PLEASE FILE AN ISSUE IN CASE OF A BUG OR ADD A COMMENT. Feel free to email me: [email protected] with issues or new problems.
I have a cloned repo https://github.com/techpanja/interviewproblemspublic which is open for contribution. Feel free to email me if you want to be a contributor.
A COMPILATION OF COMMON INTERVIEW QUESTIONS AND SOLUTIONS.
-
Given +ve numbers in an array.Put the even #s to the left of the array and the odd to the right side of the array . Don't use extra array. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/allevennumberstoleft/AllEvensToLeftandOddsToRight.java
-
Given M * N matrix find count of all distinct paths from top left cell to bottom right. You can only move downwards and to the right from a given cell. Link:
-
Given a sequence of non-negative integers find a subsequence of length 3 having maximum product with the numbers of the subsequence being in ascending order. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/ascsubsequencemaxproduct/SubsequenceProduct.java
-
Shift array of integers circularly given input array and shift size. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/circularshiftintarray/CircularShiftArray.java
-
Given a boolean matrix mat[M][N] of size M X N, modify it such that if a matrix cell mat[i][j] is 1 (or true) then make all the cells of ith row and jth column as 1. Link:
-
Check if a sub-array exists in parent array. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/findarray/FindArrayImpl.java
-
Find duplicates count in sorted array. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/findduplicatecountsortedarray/DuplicatesCountInSortedArray.java
-
Write a program takes array input{1,0,2,3} and num = 3 and provides output {1,2}{0,3}{2,1}{3,0} sum equals the num. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/findpairsequaltosum/FindPairsEqualToSum.java
-
Given a sorted array (ascending order and distinct elements), find i such that inputArr[i] = i. Return -1 if nothing found. Link:
-
Find the contiguous subarray which has the largest sum. Kadane's algorithm. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/maxsubarray/FindMaxSubArray.java
-
Given two sorted (ascending) arrays of integers, find the minimum difference between two integers in that array. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/mindiffsortedarrays/MinimumDifferenceSortedArrays.java
-
Print numbers with frequency. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/numberfrequency/PrintNumbersWithFrequency.java
-
Find Number with Highest frequency in sorted array. Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/numberwithhighestfreq/FindNumberWithHighestFreq.java
-
Given an array, write a program to generate a random permutation of array elements. Also asked as “shuffle a deck of cards” or “randomize a given array”. Link:
-
Search for a number in rotated sorted array (Ascending or Descending). Link: https://github.com/techpanja/interviewproblems/blob/master/src/arrays/searchrotatedsortedarray/SearchInRotatedSortedArray.java
-
Find cartesian of lists. Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/cartesianproblem/CartesianOfLists.java
-
Find the common elements accross sorted sets/lists. Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/commonelementsortedsets/FindCommonElementsInSortedSetsOrLists.java
-
Implement custom linked list. Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/customlinkedlist/LinkedListImpl.java
-
Check if a linked list has loops. Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/customlinkedlist/LinkedListImpl.java
-
Find nth element from end of the linked list. Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/findNTHlastelement/FindNthLastElement.java
-
Find the loop starting point in a LinkedList if it contains loop. Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/customlinkedlist/LinkedListImpl.java
-
Flatten a nested list. Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/nestedliststring/NestedList.java
-
Given a nested list of integers, returns the sum of all integers in the list weighted by their depth. Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/nestedlistsum/NestedListSum.java
-
Remove duplicate links from LinkedList. Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/removeduplicatesfromlinkedlist/RemoveDuplicatesFromLinkedList.java
-
Reverse a linked list. (In-place and using stack.) Link: https://github.com/techpanja/interviewproblems/blob/master/src/collections/customlinkedlist/LinkedListImpl.java
- Implement custom iterator. Link: https://github.com/techpanja/interviewproblems/blob/master/src/customiterator/AnimalIterator.java
-
Breadth First Search Link: https://github.com/techpanja/interviewproblems/blob/master/src/graphs/breadthfirstsearch/BFS.java
-
Depth First Search Link: https://github.com/techpanja/interviewproblems/blob/master/src/graphs/depthfirstsearch/DFS.java
-
File Dependency Resolution Link: https://github.com/techpanja/interviewproblems/blob/master/src/graphs/graph/AbstractGraph.java
-
Max Heaps Link: https://github.com/techpanja/interviewproblems/blob/master/src/heaps/heap/MaxHeap.java
-
Min Heaps Link: https://github.com/techpanja/interviewproblems/blob/master/src/heaps/heap/MinHeap.java
-
Custom HashMap implementation. Link: https://github.com/techpanja/interviewproblems/blob/master/src/maps/customhashmap/CustomHashMapImpl.java
-
Least Recently Used (LRU) cache implementation. Link: https://github.com/techpanja/interviewproblems/blob/master/src/maps/lrucache/LRUCache.java
-
Map that should be sorted on the basis of values and not keys. (Use of treemap and comparator.) Link:
-
Concatenate two numbers. for e.g. 123, 0456 = 1230456 Link: https://github.com/techpanja/interviewproblems/blob/master/src/numberproblems/concatenatenumbers/ConcatenateNumbers.java
-
Convert string to number. Link: https://github.com/techpanja/interviewproblems/blob/master/src/numberproblems/convertstringtonumber/ConvertStringToNum.java
-
Find exponential of a number in fastest time. Link: https://github.com/techpanja/interviewproblems/blob/master/src/numberproblems/exponentialnumber/ExponentialOfNumber.java
-
Find factorial of a number. Link: https://github.com/techpanja/interviewproblems/blob/master/src/numberproblems/factorial/Factorial.java
-
Find no. of trailing zeroes in a factorial of number. Link: https://github.com/techpanja/interviewproblems/blob/master/src/numberproblems/factorial/FactorialNoOfTrailingZeroes.java
-
Find missing number in stream of numbers. Link: https://github.com/techpanja/interviewproblems/blob/master/src/numberproblems/findmissingnumber/FindMissingNumber.java
-
Check if a number is odd or even without using / % * + - operators. Link: https://github.com/techpanja/interviewproblems/blob/master/src/numberproblems/oddoreven/OddOrEven.java
-
Print prime factors of a number. Link:
-
Given a number N, find the smallest number K such that product of digits of K is equal to N. For e.g. N = 100 then K = 455 Link:
-
Swap Numbers. Link: https://github.com/techpanja/interviewproblems/blob/master/src/numberproblems/swapnumbers/SwapNumbers.java
-
Cloning example (Linked List). Link: https://github.com/techpanja/interviewproblems/blob/master/src/objects/cloning/linkedlistclone/LinkedListCloning.java
-
Implement an Immutable class. Link: https://github.com/techpanja/interviewproblems/blob/master/src/objects/immutableclass/ImmutableClass.java
-
Pass by value example. Link: https://github.com/techpanja/interviewproblems/blob/master/src/objects/passbyvalue/PassByValue.java
-
Implement a singleton class. (Double-check Locking and Static) Link: https://github.com/techpanja/interviewproblems/tree/master/src/objects/singleton
-
Bubble Sort. Link: https://github.com/techpanja/interviewproblems/blob/master/src/sorting/algorithms/BubbleSort.java
-
Insertion Sort. Link: https://github.com/techpanja/interviewproblems/blob/master/src/sorting/algorithms/InsertionSort.java
-
Merge Sort. Link: https://github.com/techpanja/interviewproblems/blob/master/src/sorting/algorithms/MergeSort.java
-
Quick Sort. Link: https://github.com/techpanja/interviewproblems/blob/master/src/sorting/algorithms/QuickSort.java
-
Selection Sort. Link: https://github.com/techpanja/interviewproblems/blob/master/src/sorting/algorithms/SelectionSort.java
-
Shell Sort. Link: https://github.com/techpanja/interviewproblems/blob/master/src/sorting/algorithms/ShellSort.java
-
Custom Stack with push(), pop() and getMin(). Link:
-
Check if opening parenthesis pattern matches closing parenthesis pattern. Link: https://github.com/techpanja/interviewproblems/blob/master/src/stackqueues/parenthesismatching/ParenthesisMatching.java
-
Implement a queue using stack. Link: https://github.com/techpanja/interviewproblems/blob/master/src/stackqueues/queueusingstack/QueueUsingStack.java
-
Sort a stack using only one additional stack and no other data structure. Link: https://github.com/techpanja/interviewproblems/blob/master/src/stackqueues/stacksorting/StackSorting.java
-
Check string palindrome. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/checkpalindrome/CheckPalindrome.java
-
Find minimum distance between two words (order preserved. Followup: Unpreserved order.) in a big string. (Kadane's Algo) Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/distancebetweenwords/DistanceBetweenWords.java
-
Find common prefix for a given list of strings. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/findcommonprefix/CommonPrefix.java
-
Find duplicate strings in list of strings. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/findduplicates/FindDuplicates.java
-
Find latest version problem. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/findlatestversion/FindLatestVersion.java
-
Find Longest Common Subsequence. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/findlongestcommonsubsequence/LCS.java
-
Find Longest Palindrome in a string. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/findlongestpalindrome/FindLongestPalindrome.java
-
Print permutations of all characters in a string. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/findpermutations/FindPermutations.java
-
Find total number of palindromes in a String. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/findtotalpalindromes/FindTotalNoOfPalindromes.java
-
Find first non-repeated character. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/firstnonrepeatedchar/FirstNonRepeatedChar.java
-
Given two (dictionary) words as Strings, determine if they are isomorphic. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/isomorphicstrings/Isomorphic.java
-
Given s string, find max size of a sub-string, in which no duplicate chars present. (Kadane's Algo) Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/longestsubstringnorepeatedchar/LongestSubstringUnrepeatedChar.java
-
Find min substring that contains all the char of target string. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/minimumsubstringcontains/MinimumSubstring.java
-
Print diamonds on basis of input size. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/printdiamonds/PrintDiamonds.java
-
Identify all the 'n' (n will be input) letter-long sequences that occur more than once in any given input string. OR Find repeating sequence of specified length in given DNA chromosome sequence. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/repeatingstringsofspecifiedlength/RepeatingStringOfSpecificLength.java
-
Reverse a string. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/reversestring/ReverseString.java
-
Find all dictionary words in a given string. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/segmentstringfindalldictwords/StringSegmentation.java
-
Return true if stringA is subsequence of stringB. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/stringsubsequencecheck/CheckStringSubsequence.java
-
Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/substringcheckforrotatedstring/RotatedStringSubStringCheck.java
-
Check if a string has all unique characters. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/uniquecharscheck/CheckUniqueCharacters.java
-
Count word occurrence in a large text file. Link: https://github.com/techpanja/interviewproblems/blob/master/src/strings/wordcountinlargefile/WordOccurencesInLargeFile.java
-
Implement blocking queue. Link: https://github.com/techpanja/interviewproblems/blob/master/src/threads/blockingqueue/BlockingQueue.java
-
Simulate a deadlock. Link: https://github.com/techpanja/interviewproblems/blob/master/src/threads/simulatedeadlock/DeadLockOreilly.java
-
Check Balanced Tree. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/checkbalancedtree/CheckBalancedTree.java
-
Check if a tree is Subtree of parent tree. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/checksubtree/CheckSubtree.java
-
Find common ancestor of two nodes in a binary tree (not necessarily BST). Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/commonancestorbinarytree/CommonAncestorBinaryTree.java
-
Find diameter Of Tree. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/diameteroftree/DiameterOfTree.java
-
Find All Paths Equal To Sum. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/findallpathsequaltosum/FindAllPathsEqualToSum.java
-
Find Sum Of All Nodes Except Leaf. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/findsumofallnodesexceptleaf/FindSumOfAllNodesExceptLeaf.java
-
Check is a given tree is binary search tree. (recursive and non recursive) Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/isbst/CheckIfTreeIsBst.java
-
Find least common ancestor (LCA) of a binary search tree given two nodes. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/leastcommonancestorbst/FindLeastCommonAncestorBST.java
-
Left View of a Tree. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/leftviewofatree/LeftViewOfATree.java
-
Mirror Given Tree. Link:
-
Check if a tree is Mirror of another Tree. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/mirrortree/MirrorTree.java
-
Print Nary Tree With Levels. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/printnarytreewithlevels/PrintNaryTreeWithLevels.java
-
Given a sorted array, create a balanced tree. Link: https://github.com/techpanja/interviewproblems/blob/master/src/trees/sortedarraytobalancedtree/SortedArrayToBalancedTree.java
*** NOTE: Some problems might be in-complete. I have added TODO for such problems. ***