Killer Problems
- Quick sort - Inplace partition
- AtoI and ItoA conversion
- Base conversion problems
- Verify if all the characters in a given string are unique or not
- Remove all the duplicates in a given string - Linked HashSet
- insertion Sort
- Merge Sort
- Binary Search - recursive and non-recursive
- Stack - Datastructure - PUSH, POP, PEEK
- Queues - DataStructure - INSERT, REMOVE, ...
- Circular Queues - "
- LInked Lists SLL
- Linked Lists DLL
- Linked List XOR based LL
- Concatenate two linked lists
- Reverse a SLL
- Reverse a DLL
- Circular SLL
- Lowest Common ancestor if an any given two nodes
- 2 sorted arrays of non-repeating integers. Find min(abs(x-y))
- Maximum value of continours sub sequence Kadane Algorithm
- Given repeated sorted array and a number, Tell its first and last idex
- Reverse the words in a given sentence
- Find an element in rotated binary sorted array
- Find an element that is repeated more than n/2 times
- Implement power function (a)b
- Check if a given linked list is cyclic or not
- Find a pair in an array that sum up to a number
- Reverse a pair of nodes in a SLL
- Seggregate odd/even number of nodes in a given Linked list
- Find the middle of a SLL
- Addition of 2 linked lists
- XOR based linked list - Insert, delete and display
- Convert SLL to DLL
- Circular shift an array of size n
- Find the minimum element in a rotated sorted array
- Pattern Matching - Rabin Karp Algorithm
- K-way merge sort
- Maximum Depth or Height a a given tree
- Find all the subsets of a given set of integers
- Find the inorder successor a given node in BST
- Heapsort
- Find the minimum length of unsorted subarray to make whole array as sortd
- Suffix arrays
- Print all the permutations of a given stirng
- Rearrange a stirng such that all the same characters be 'd' distant away
- Rat in a Maze 0,0 to 7,7 ?
- Find all the subset of elements in a given set whose sum equal to a target
- Find if there is a subarray with sum 0
- Find the median of given two input sorted arrays
- Find the fixe dpoint a[3]=3 or a[1]=1 in a given sorted arary
- Count # of key occurrences of a number in sorted array
- Check if a given number is a multiple of 3 or not
- Check if a number 'n' is power of 2 or not
- Function to multiply n by 7
- Multiply 2 numbers without * operator
- Generate all prime numbers smaller than equal to n [Sieve of Erathosenes]
- Make a fair coin from unbiased coin
- Print all the possible words from phone digits
- Shuffle a given array / Randomize a given array of integers - Fisher Yates
- Reservior sampling - Select 'k' random elements from a stream with k/n probability
- Given a number 'n'. Generate a Pascal Triangle
- Generate all prime factors of a given number ;n;
- Random number generator in arbitrary probability Distribution function
- Check if a given number is fibonacci number or not
- Longest common Subsequence
- Minimum cost path, Find the cost of traversing from 0.0 to m,n
- Coing change problem
- Binomial co-efficient via Pascal Triangle ?
- Knapsack problem
- Egg drop problem
- Longest palindromic subsequence
- Palindrome Partitioning. Determine minumum number of cuts to make substrings as palindromes
- Partitioning problem - Two sets with equal sum
- Maximum length chain of pairs
- Check if a given linked list is a palindrome or not [stack or reverse]
- Given a post order + Inorder array, Check whether array is BST or not
- Array with bits 0110101101, flip them such that it has max number of 1's in it
- Implement sizeof() operator
- Find inorder successor of a BST
- Find all the triangle triplets in an array
- Josephus problem
- Given a sorted skewed binary tree, createa a BST out of it
- Return all elements in an array that are repeated twice only
- Given an array, put all even numbers to left of array and odd numbers to right of array
- Height of a given tree
- Diameter of a given binary tree
- Serialize/Deserialize a given binary tree
- Find the just single repeated element in a a given array
- Implement diff command in linux
- Program to count number of 1's in a given number
- Convert BST to DLL
- Swap variables withour a temp
- check if a number is prime or not
- GCD of 2 numbers - Euclidean Algorithm
- Median of a stream of numbers continous
- Print all the paths of a given binary tree from root to leaf
- Modify/Relocate an array such that a[i] = a[a[i]]
- Find a missing number in 4 Billion Numbers
- Given 'n', Generate all valid paranthesis string of length 2n
- Rectangle intersection problem - Find if rectangles overlap and area of rectangles
- Dutch National Flag Problem 0-1-2
- Increment an arbitrary precision integer, Stored in an array
- Advancing through an array to reach end
- Delete duplicates from a sorted array
- buy and sell a stock once
- buy and sell a stock multiple times
- permute all the elemtns of an array
- Compute next permutation represented 'n' as in an array
- Random Sampling
- Sample online data
- Sudoku Checker Problem [Backtracking]
- Sudoku Checker Problem - validate if its a correct sudoku
- Base Conversion n(b1) to n(b2)
- Given a column number, Find the corresponding column name in a excel spreadsheet
- Char replacement in a string, Replace 'a' with 'dd', Remove 'b'
- Validate if a given sentence is a palindrome or not
- Look and Say Sequence, Given n, output nth number in the sequence
- convert form roman numeral to decimal number
- compute all the valid IP addresses
- write a string sinusoidally - since wave fashion
- Implement a runlength encoding algorithm
- Merge 2 sorted linekd lists
- Reverse a sublist of a given linked lists
- Verify if a given tree is height balanced or not
- Total # of nodes on longest path between 2 leaves in a tree, AKA Diameter of a given tree
- Sum root-to-leaf paths in a binary tree
- Given a BT, Return true if it has root-to-leaf path sum adding up to all values along the path equal to a given number
- Implement inorder traversal without recursion - Morris Traversal
- Implement inorder traversal with a stack
- Iterative pre-order traversal
- Iterative post-order traversal
- Compute value of kth smallest node in a binary tree
- Reconstruct a binary tree from a given traversal data (inorder + Pre or Post)
- Construct a DLL from leaves of a binary tree
- Print boundary of a given binary tree
- Priority queues using Heaps
- Convert Minheap to Max heap
- check if a given binary tree is a heap or not
- Check if a given BT is complete or not
- Check if a given array represents max heap or not
- Given a infinite stream, Find the kth largest element at any point of time
- Merge 'k' sorted arrays - external Sorting
- Ternary search
- Level order traversal of a binary tree
- Heap - Insertion, Deletion to max heap - Priority Queues
- Verify if 2 strings are anagrams or not
- Longest increasing sub sequence
- Given 2 string and operations (insert, delete and replace) can be done on str1, Find the minimum number of edits required to convert str1 to str2
- Rod cutting, Max value obatined by cutting rod of 'n' length + Price and values are considered
- Maximum sum increasing subsequence
- Longest biotonic subsequence
- Floyd Warshall Alogorithm
- Minimum number of jumps required to reach end
- Pattern searching - KMP Knuthh Morris Pattern Algo
- Given n+2, find the 2 repeated elements from 0 to n
- Lowest common ancestor in a BST
- Find inorder predecessor and successor in a BST
- Delete a node in BST - 3 cases
- merge two BSTs with limited extra space
- Find ceil and floor value of a given key in a BST
- Binary trees - Full, complete, Perferct, balanced ?
- Size of a binary tree
- Convert a Binary tree in to its mirror tree Inplace post order
- Count # of leaf nodes in a binary tree
- Check for childrem sum property in a given binary tree
- maximum width of binary tree - i.e find a level that contains maximum number of nodes
- Check if a tree is foldable or not
- Print all the nodes with distance 'k' apart from the root
- Get level of a node in a binary tree
- Print ancestors of a given node in binary tree
- Check if a binary tree is a subtree of another binary tree
- Connect nodes at same level in a binary tree - extended level order
- Populate inorder successor nodes of all nodes in a binary tree - Reverse inorder
- Convert given tree to its sum tree
- Find the maximum sum from root to leaf in a BT
- Print the boundary of a BT
- Construct a Full BT form given pre-order & post order. There are other possible combinations of traversals too
- Iterative post-order traversal using stacks
- Reverse level order traversal 2 stacks
- Count BST nodes that lie in a given range low, high
- Clone a linkedlist with next and random pointer
- Wildcard pattern matching . ? *
- Implement a stack using queues
- Implement a queue using stacks
- generate a random number in a range
- Select a random node in a given SLL
- Check if a number is a palindrome or not
- Existenece of increasing triplet in a sequence
- Sum of all the numbers that are formed from root to leaf path
- Find all the possible words in a given word boggle. you can assume a routine being provided to check if a word exists in a dictionary or not
- Longest path in a given matrix
- Find the peak element in an given array
- Four array sum problem a[i] + b[j] + c[k] + d[l] whose sum is zero
- Verify if string 't' is a subsequence of another string 's'
- Remove duplicates from sorted arrays. how about if we allow max number of duplicate elements
- Submatrix sum queries. Given (r1,c1) and (r2,c2)
- Four sum problem such that a+b+c+d = target
- Partition a given linked list with values across 'x'
- Find the sum of all digits in a number recursively until it becomes a single digit
- Longest continuous/consecutive sub sequence - DP
- Implement a trie/prefix trees
- Sort a hashMap<k,v> based on values
- Sort the elements based on frequence Ex: tree -> eetr
- sum of two number without +,-,*,/
- Repeated DNA subsequence maxlength =10, AGCT
- Flight Drone Fuel
- A product array puzzle, a[i] = prod(0-i-1 & r+1 to n)
- Word count engine, Given a doc - count number of words
- Count number of possible triangles in a given array
- Find the # of leaders in a given array
- Find the sub array continous sum equal to a target
- Find the equilibrium index of a given interger array
- Minimum number of paltforms required for a railway station given the arrival and departure of the trains
- Find the maximum of all subarrays of size k
- Find the kth smallest or kth largest element in a given array
- Trapping Rain Water - Find the max amount of water that can be stroed in a given hieght of bridges repesented as an array
- Chocolate distribtuion problem - Find the minimum difference such tath every m student gets a packet and the diff of min and max packet received by a student is minimal
- Find an elemtn with all left side smaller and all right side elements are greater
- Convert a givne unsorted array in to zig zag fashion [a>b<c>d<e>f...]
- Relative Sorting - Sort an array according to the order defined by another array
- Traverse the matrix in a sprial way
- Arrange the given numbers in an array to form the biggest number
- Largest sub array with equal number of 0s and 1s
- Check if a string has valid set an order of paranthesis
- Largest palindrome in a given string
- Recursively remove all the adjacent duplicates characters progressively - azxxzy
- Check if a given string is rotated by two places
- Find the longest common substring in given two strings
- Given a string, Find the minimum # of characters to be inserted to convert to a plindrome
- Find the longest substring with all distinct characters
- Implement a string indexOf method
- Given an array of String, Find the longest common prefix
- Given an unsorted array. Find the continous subarray that adds upto a target
- A special linked list with next and random pointer with each list sorted, Flatten it in sorted order
- Find the intersection point or merge point in the linkedlist
- Find the next largest element to right of the array
- Get the minimum element from a stack at any given point of time 't'
- Given (capacity, distance), Find a starting point to circle the tour
- Given infinity stream, Find the first non-repeating character
- Print the left view of Binary tree
- Print bottom view of binary tree
- Print right view of binary tree
- Print vertical order of binary tree
- Print level order of a tree traversal in spiral form
- Print level order of a tree in reversal form
- Given a binary tree in which each node contains a number, Find the max possible sum from one leaf node to another leaf node
- Find the median in a infinite stream of interegers
- Given a string repated characters, the task is to rearrange the chanracters in a string such that no two adjacent characters are same
- Given a 2D screen, location of a pixek in a screen and a color k, Repalce all such pixels with color 'y'
- Count all possible paths from top left to right bottom. i,e 0,0 to m,n only right n down directions are allowed
- Given an integer array and a target N , Find all the unique combinations in A where sum is equal to target. element can be used only once.
- Same as above question, but what if element can be used any nnumber of times
- Given n of keystorkes allowed, Find the max A's that can be printed if permissible keystrokes are - ctrl+A, ctrl+c, ctrl+v and A
- Find the largest subarray with 0 sum
- Given two array of integers, Find the two arrays sum be equal of swapping atmost one integer ?
- Given an array of integers, and window 'k' , Print the count of distinct numbers in all windows of size k
- GIA (Given Integer array), Find if an array can be divided in to pairs such that sum of every pair is divisible by 'k'
- GIA, Find the length of longest consecutive subsequence
- Find if one integer array is subset of another array
- Given two unsorted arrays, Find all the pairs from both arrays where sum is equal to x
- Find the first repeated character in a given string s
- GIA, Print the total count of subarrays with their sum equal to 0
- Given a string and pattern, Find the character in a string that is present at minimum index in a second string.
- Find the uncommon character of two string . A uncommon character is something i.e present in one string or other but not both
- Find the smallest window in a string that contains all characters in another string
- GIA, Find the first element that occurs k number of times
- Given a string, Check if its possible to remove atmot one character such that frequencies of all characters of each distinct chracter becoms same in a string
- Depth first traversal of a graph
- Breadth First Traversal of a graph
- Detect a cycle in a directed graph
- Given set of vertices and edges, Sort them in a topological order
- Find the number of islands in a given 0/1 matrix
- Find the shortest distance from source to all destination vertices [Djikstra]
- Find the minimum number of swaps required to sort an integer array
- Given a graph with n nodes and m edges, Find the total number of strongly connected components
- Given a binary 0/1 matrix, Find the shortest path that exists from a given source to destination cell (LEE algorithm)
- Given n*n matrix with 0,1,2,3. Find whether a path exists from source 1 to destination 2 via cell 3. 0 - means blocked
- Circle of Strings, Given a list of strings, Find whether we can form a circle from start and last character ?
- Find the minimum number of jumps required to reach end
- Find the # of ways to make a change for N cents if infinite supply of coins exist
- Find the minimum coins required to make change for N cents on infinite supply of coins
- Partition Problem - Find if an array can be partitioned into two subsets such that their sum is equal
- Sort Stack the boxes of N types. Each box has l,d and h. Create a stack of boxes as tall as possible. You can rotate the boxes if needed
- Find the longest path in the matrix such that all cells along the path are in increasing order with a difference of 1
- same as above but just with increasing path without constraint of diff 1
- Find an element that appears only once in sorted order
- Find kth element in two sorted arrays
- Find the last index of '1' , Given an array of 0s and 1s
- Find the first set bit in an integer
- Given two integers, Find the right most different bit
- Given an integer, Find if kth bit is set from right or not
- Check if a given integer is power of 2 or not
- Given 2 integers, Find the # of bits differ in each integer
- Find the total number os longest consecutive 1's in an integer
- Find the most frequesnt word in a given list or array of strings
- Find the median of two sorted arrays
- Given an array, find the maximum (j-i) such that a[j] >= a[i]
- Given a sentence, Output a string by dropping a seen character alternatively.
- Find if one can reach end of the array assuming a[i] being the number of cells to jump
- Print all the elements in a sorted from a row and columnwise sorted matrix
- Search an element in a row and column wise sorted matrix
- Regular Expression - Search for a pattern with ? * in the text
- Delete a node in the middle of single linked list. Only a pointer to middle node is given
- Find the three closest elements from a given three sorted arrays such that a[i]-b[j], b[j]-c[k], c[k]-a[i] is minimum
- Find the largest rectangular histogram
- Maximum size square of submatrix that has all 1's
- Find all the triplets with 0 sum in an array
- Max product sub array
- Sliding Window Maximum, Find the max of 'k' in window
- Largest submatrix sum of size k
- Word Boggle - Given a 2D char matrix, Find if the word exists in a given grid.
- Word Boggle 2 - Given a dictionary of words, Return all the words that exist in a grid
- Word Break - Given a dictionary of words and a concatenated string, Ensure if you can segement the concat string based on dictionary words
- Merge all the overlapping interval pairs
- Given 2 sorted lists, merge in to single list by merging intervals
- Count the number of ways to reach n stairs
- Find the closest leaf node in a Binary tree
- Add bold tag in the string
- Merge two binary trees
- Find the closest time given HH:MM
- Reverse an integer
- Find the largest value in a tree at each level
- Find the # of ways of climbing steps to top . Max of 1-2 stops each time
- Find palindrome pairs in a given list of words
- Word Square - Find the word [row, column] of fixed length
- Set Matrix Zeros - Replace a row and its respective column to 0
- Find the median of 'k' elements of sliding window
- Word Ladder Problem. Find the minimum traversals in a dictionary to reach target
- Find the longest valid parentheses in a given string
- Given an integer, Find the possible ways to decode it. a-1, b-2...z-26
- Clone a undirected graph
- Implement calculator - Given a expression string
- Implement a program to version matching. major.minor.subminor
- Implement Tic Tac Toe Game
- Design and Implement a hit counter
- Implement a BST Iterator - hasNext and next
- Implement a array iterator - hasnext and next
- Implement a list of list iterator - hasnext and next and remove methods
- Palindrome Partitioning - Find the minimum number of cuts required to make a string palindrome substrings
- Convert an integer to words - similar to how you write in check leaf
good collection.
ReplyDeletecan u provide solutions in java
The answers to these questions should be available online anywhere with a simple google search. But I would recommend you to attempt and think before referring to any solutions up front.
ReplyDelete