List of some of the famous coding interview questions and their solutions.
NextGreaterElement - The Next greater Element for an element x
is the first greater element on the right side of x
in array. Elements for which no greater element exist, consider next greater element as -1
.
PythagorasTriplets - Given an array, find if it contains the Pythagoras Triplets. Triplet (a,b,c)
such that a^2 + b^2 = c^2
.
Three Sum Problem - Given an array and a value, find if there is a triplet in array whose sum is equal to the given value.
StockSpan - https://www.geeksforgeeks.org/the-stock-span-problem/
LongestIncreasingSubsequence - https://www.interviewbit.com/problems/longest-increasing-subsequence/. Find the number of elements in the longest increasing subsequence.
Maximum Difference between two elements - https://www.geeksforgeeks.org/maximum-difference-between-two-elements/ - Maximum difference between two elements such that larger element appears after the smaller number.
RotateMatrixBy90Degree - Given a n * n
matrix, rotate its element by 90 degrees.
FibonacciSeries (Dynamic Programming) - Find Fibonacci series upto N.
FindAllPrimeNumbersInRange - Find all prime numbers in a given range (N, M)
FindMissingNumbersInIncreasingArray - Given an array which has numbers from [1...N] find the missing number.
Add2NumbersRepresentedByLL - Given two numbers represented by two lists, write a function that returns sum list. The sum list is list representation of addition of two input numbers.
MergingPointOf2Liists - Given the pointers to the head node of 2 lists which will surely merge, find the merging point (node), at which they merge.
ReverseLinkedListInGroup - Reverse Linked List within a group of k
elements. For example, if the list is 1 -> 2 -> 3 -> 4 -> 5 ->6 -> 7
and k = 3
, then output list will be 3 -> 2 -> 1 -> 6 -> 5 -> 4 -> 7
.
SetForGivenArray - Create set consisting of all the possible combinations of elements, for a given array.
FirstRecurringCharacter - Find the first recurring character within a given string.
AllSubstringPalindromes - Given a string, find all the substrings of that string which are palindrome
ReplaceACharWithAWord - Replace a single char of a String, with a word (String replace without using Java built-in functions)
TwoStringAnagram - Find of 2 strings are Anagrams
"Write your own" interview questions, tests your ability of understanding a particular concept or data structure.
HashMap - HashMap is a hash based Key-Value pair data structure, which will give O(1)
time complexity for put and get operations. "Write-your-own" HashMap is a famous Java data structure based interview question to understand, how deep you know about this famous data structure.
LRUCache - LRU Cache - is a key-value pair, which is of fixed length. Whenever the capacity of the cache reaches to MAX, then it evicts the "Least Recently Used" key.
FastDS - A custom data structure, which performs add, delete, get and getRandom() operation @ O(n) complexity
HeightOfBinaryTree - is a recursive way of finding the height of a binary tree (height of binary tree - max (height of left sub-tree, height of right sub-tree)
Column Wise Sum of Binary Tree - Column wise sum of binary tree
Zig Zag Traversal on Binary Tree - Zig Zag traversal on binary tree (level order) using 2 stacks
Check if 2 binary trees are identical - Using recursion to find out if 2 binary trees are identical
RightView - Right view of the Binary Tree
TopView - Top view of the Binary Tree
Traversal - All 3 traversals of Binary Tree (Inorder, Preorder and Postorder)
LevelOrderTraversal - Level order Traversal of the Binary Tree
ReverseLevelOrderTraversal - Reverse Level order Traversal of the Binary Tree
BinartTreeToSumTree - Binary tree to the sum tree problem. Each parent node will have a value = cumulative (left node value + right node value)