Author: Vijay SRJ

  • Delete Node in a Linked List given only the node

    Problem: You are given a node to delete from a linked list. But you are not given the head node. Delete it in O(1) time and O(1) space complexity. Constraints: For example, Given the linked list : 1 -> 4 -> 7 -> 8 And the node 7 to be deleted The output should be…

  • Course Schedule II

    Problem : Given an integer array representing prerequisites of different courses and the total number of courses , find out the order in which the courses should be taken. For example, if the given input is [1,0] It means to take course 1 you should have completed course 0. Or in other words, Course 0…

  • Odd Even Linked List

    Problem: Given the head of a linked list , reorder the linked list so that the elements in odd indices are grouped together followed by the elements in event indices. The first index is assumed to be 1 (odd) and the second index even and so on. For example, For the below input: 1 ->…

  • Find first and last position of element in sorted array

    Problem: Given a sorted integer array find the first and last position of given target element For example, If given array is [ 1,3,6,6,7,9] and target is 6 Then output is [2,3] which represents the first and last index position of the element 6 For the same input if the target is 8 Then the…

  • Rotate Array

    Problem: Given an integer array and a number k , rotate the array by k positions to the right. For example, If the given array is [1,2,3,4,5,6,7,8] and k = 4 Then the output is [5,6,7,8,1,2,3,4] Pushing an element out of the array makes it land in the beginning of the array. Try out the…

  • Find the next highest permutation of an array

    Problem: Given an integer array , find the next highest permutation of the numbers. If the next highest permutation is not found return the smallest permutation of the given input. Permutation of a number is all possible combinations of the given numbers. For example, Given the array: [1,2,3] The possible permutations are [1,3,2] , [2,1,3],…

  • Find if a linked list is a palindrome or not

    Problem: Given the head of a linked list , find if it is a palindrome or not. Find the solution in O(n) time and in place (O(1) space complexity) For example , the below linked list : 1 -> 2 -> 2 -> 1 is a palindrome The below is not: 1 -> 5 ->…

  • Convert Excel Sheet Column Title to Number

    Problem: Given an excel sheet column title , convert it to the column value. For example, Column value of sheet number ‘A’ is 1 ‘Z’ is 26 ‘AA’ is 27 ‘BA’ is 53 and so on. Constraints: Try out the solution here; https://leetcode.com/problems/excel-sheet-column-number/ Solution: If it is a single letter we can return the value…

  • First Unique Character in a String

    Given a string find the index of the first unique character (non repeating). For example, For the string “see” the output is 0 since the letter s is not repeated in the string For the string “bbaaddavt” the output is 7 because the letter v is not repeated and is present in index 7. Assumption:…

  • Find Peak element in an array

    Problem: Given an integer array return the index of any peak element in it. Find a solution in O(logn) time. A peak element is an element which is greater than its neighbors. Its neighbors are the immediate elements to its left and right. you can return any peak element. So for example , if the…