450 Questions
450 Questions
Array
(1) Reverse the array
(2) Find the maximum and minimum element in an array
(3) Find the "Kth" max and min element of an array
(4) Given an array which consists of only 0, 1 and 2. Sort the array without
using any sorting algorithms
(5) Move all the negative elements to one side of the array
(6) Find the Union and Intersection of the two sorted arrays.
(7) Write a program to cyclically rotate an array by one.
(8) find Largest sum contiguous Subarray [V. IMP]
(9) Minimise the maximum difference between heights [V.IMP]
(10) Minimum no. of Jumps to reach end of an array
(11) find duplicate in an array of N+1 Integers
(12) Merge 2 sorted arrays without using Extra space.
(13) Kadane's Algo [V.V.V.V.V IMP]
(14) Merge Intervals
(15) Next Permutation
(16) Count Inversion
(17) Best time to buy and Sell stock
(18) find all pairs on integer array whose sum is equal to given number
(19) find common elements In 3 sorted arrays
(20) Rearrange the array in alternating positive and negative items with O(1) extra space
(21) Find if there is any subarray with sum equal to 0
(22) Find factorial of a large number
(23) find maximum product subarray
(24) Find longest coinsecutive subsequence
(25) Given an array of size n and a number k, fin all elements that appear more than " n/k " times.
(26) Maximum profit by buying and selling a share atmost twice
(27) Find whether an array is a subset of another array
(28) Find the triplet that sum to a given value
(29) Trapping Rain water problem
(30) Chocolate Distribution problem
(31) Smallest Subarray with sum greater than a given value
(32) Three way partitioning of an array around a given value
(33) Minimum swaps required bring elements less equal K together
(34) Minimum no. of operations required to make an array palindrome
(35) Median of 2 sorted arrays of equal size
(36) Median of 2 sorted arrays of different size
Matrix Problems
(1) Spiral traversal on a Matrix
(2) Search an element in a matrix
(3) Find median in a row wise sorted matrix
(4) Find row with maximum no. of 1's
(5) Print elements in sorted order using row-column wise sorted matrix
(6) Maximum size rectangle
(7) Find a specific pair in matrix
(8) Rotate matrix by 90 degrees
(9) K’th smallest element in a row-column wise sorted matrix
(10) Common elements in all rows of a given matrix
String Problems
(1) Reverse a String
(2) Check whether a String is Palindrome or not
(3) Find Duplicate characters in a string
(4) Why strings are immutable in Java?
(5) Write a Code to check whether one string is a rotation of another
(6) Write a Program to check whether a string is a valid shuffle of two strings or not
(7) Count and Say problem
(8) Write a program to find the longest Palindrome in a string.[ Longest palindromic Substring]
(9) Find Longest Recurring Subsequence in String
(10) Print all Subsequences of a string.
(11) Print all the permutations of the given string
(12) Split the Binary string into two substring with equal 0’s and 1’s
(13) Word Wrap Problem [VERY IMP].
(14) EDIT Distance [Very Imp]
(15) Find next greater number with same set of digits. [Very Very IMP]
(16) Balanced Parenthesis problem.[Imp]
(17) Word break Problem[ Very Imp]
(18) Rabin Karp Algo
(19) KMP Algo
(20) Convert a Sentence into its equivalent mobile numeric keypad sequence.
(21) Minimum number of bracket reversals needed to make an expression balanced.
(22) Count All Palindromic Subsequence in a given String.
(23) Count of number of given string in 2D character array
(24) Search a Word in a 2D Grid of characters.
(25) Boyer Moore Algorithm for Pattern Searching.
(26) Converting Roman Numerals to Decimal
(27) Longest Common Prefix
(28) Number of flips to make binary string alternate
(29) Find the first repeated word in string.
(30) Minimum number of swaps for bracket balancing.
(31) Find the longest common subsequence between two strings.
(32) Program to generate all possible valid IP addresses from given string.
(33) Write a program tofind the smallest window that contains all characters of string itself.
(34) Rearrange characters in a string such that no two adjacent are same
(35) Minimum characters to be added at front to make string palindrome
(36) Given a sequence of words, print all anagrams together
(37) Find the smallest window in a string containing all characters of another string
(38) Recursively remove all adjacent duplicates
(39) String matching where one string contains wildcard characters
(40) Function to find Number of customers who could not get a computer
(41) Transform One String to Another using Minimum Number of Given Operation
(42) Check if two given strings are isomorphic to each other
(43) Recursively print all sentences that can be formed from list of word lists
Binary Trees
(1) level order traversal
(2) Reverse Level Order traversal
(3) Height of a tree
(4) Diameter of a tree
(5) Mirror of a tree
(6) Inorder Traversal of a tree both using recursion and Iteration
(7) Preorder Traversal of a tree both using recursion and Iteration
(8) Postorder Traversal of a tree both using recursion and Iteration
(9) Left View of a tree
(10) Right View of Tree
(11) Top View of a tree
(12) Bottom View of a tree
(13) Zig-Zag traversal of a binary tree
(14) Check if a tree is balanced or not
(15) Diagnol Traversal of a Binary tree
(16) Boundary traversal of a Binary tree
(17) Construct Binary Tree from String with Bracket Representation
(18) Convert Binary tree into Doubly Linked List
(19) Convert Binary tree into Sum tree
(20) Construct Binary tree from Inorder and preorder traversal
(21) Find minimum swaps required to convert a Binary tree into BST
(22) Check if Binary tree is Sum tree or not
(23) Check if all leaf nodes are at same level or not
(24) Check if a Binary Tree contains duplicate subtrees of size 2 or more [ IMP ]
(25) Check if 2 trees are mirror or not
(26) Sum of Nodes on the Longest path from root to leaf node
(27) Check if given graph is tree or not. [ IMP ]
(28) Find Largest subtree sum in a tree
(29) Maximum Sum of nodes in Binary tree such that no two are adjacent
(30) Print all "K" Sum paths in a Binary tree
(31) Find LCA in a Binary tree
(32) Find distance between 2 nodes in a Binary tree
(33) Kth Ancestor of node in a Binary tree
(34) Find all Duplicate subtrees in a Binary tree [ IMP ]
(35) Tree Isomorphism Problem
Back Tracking
(1) Rat in a maze Problem
(2) Printing all solutions in N-Queen Problem
(3) Word Break Problem using Backtracking
(4) Remove Invalid Parentheses
(5) Sudoku Solver
(6) m Coloring Problem
(7) Print all palindromic partitions of a string
(8) Subset Sum Problem
(9) The Knight’s tour problem
(10) Tug of War
(11) Find shortest safe route in a path with landmines
(12) Combinational Sum
(13) Find Maximum number possible by doing at-most K swaps
(14) Print all permutations of a string
(15) Find if there is a path of more than k length from a source
(16) Longest Possible Route in a Matrix with Hurdles
(17) Print all possible paths from top left to bottom right of a mXn matrix
(18) Partition of a set into K subsets with equal sum
(19) Find the K-th Permutation Sequence of first N natural numbers
Heap Problems
(1) Implement a Max heap/Min Heap using arrays and recursion.
(2) Sort an Array using heap. (Heap Sort)
(3) Maximum of all subarrays of size k.
(4) “k” largest element in an array
(5) Kth smallest and largest element in an unsorted array
(6) Merge “K” sorted arrays. [ IMP ]
(7) Merge 2 Binary Max Heaps
(8) Kth largest sum continuous subarrays
(9) Leetcode- reorganize strings
(10) Merge “K” Sorted Linked Lists [V.IMP]
(11) Smallest range in “K” Lists
(12) Median in a stream of Integers
(13) Check if a Binary Tree is Heap
(14) Connect “n” ropes with minimum cost
(15) Convert BST to Min Heap
(16) Convert min heap to max heap
(17) Rearrange characters in a string such that no two adjacent are same.
(18) Minimum sum of two numbers formed from digits of an array
Graph Problems
(1) Create a Graph, print it
(2) Implement BFS algorithm
(3) Implement DFS Algo
(4) Detect Cycle in Directed Graph using BFS/DFS Algo
(5) Detect Cycle in UnDirected Graph using BFS/DFS Algo
(6) Search in a Maze
(7) Minimum Step by Knight
(8) flood fill algo
(9) Clone a graph
(10) Making wired Connections
(11) word Ladder
(12) Dijkstra algo
(13) Implement Topological Sort
(14) Minimum time taken by each job to be completed given by a Directed Acyclic Graph
(15) Find whether it is possible to finish all tasks or not from given dependencies
(16) Find the no. of Islands
(17) Given a sorted Dictionary of an Alien Language, find order of characters
(18) Implement Kruksal’sAlgorithm
(19) Implement Prim’s Algorithm
(20) Total no. of Spanning tree in a graph
(21) Implement Bellman Ford Algorithm
(22) Implement Floyd warshall Algorithm
(23) Travelling Salesman Problem
(24) Graph ColouringProblem
(25) Snake and Ladders Problem
(26) Find bridge in a graph
(27) Count Strongly connected Components(Kosaraju Algo)
(28) Check whether a graph is Bipartite or Not
(29) Detect Negative cycle in a graph
(30) Longest path in a Directed Acyclic Graph
(31) Journey to the Moon
(32) Cheapest Flights Within K Stops
(33) Oliver and the Game
(34) Water Jug problem using BFS
(35) Water Jug problem using BFS
(36) Find if there is a path of more thank length from a source
(37) M-ColouringProblem
(38) Minimum edges to reverse o make path from source to destination
(39) Paths to travel each nodes using each edge(Seven Bridges)
(40) Vertex Cover Problem
(41) Chinese Postman or Route Inspection
(42) Number of Triangles in a Directed and Undirected Graph
(43) Minimise the cashflow among a given set of friends who have borrowed money from each other
(44) Two Clique Problem
Trie Problems
(1) Construct a trie from scratch
(2) Find shortest unique prefix for every word in a given list
(3) Word Break Problem | (Trie solution)
(4) Given a sequence of words, print all anagrams together
(5) Implement a Phone Directory
(6) Print unique rows in a given boolean matrix
Dynamic Programming
(1) Coin ChangeProblem
(2) Knapsack Problem
(3) Binomial CoefficientProblem
(4) Permutation CoefficientProblem
(5) Program for nth Catalan Number
(6) Matrix Chain Multiplication
(7) Edit Distance
(8) Subset Sum Problem
(9) Friends Pairing Problem
(10) Gold Mine Problem
(11) Assembly Line SchedulingProblem
(12) Painting the Fenceproblem
(13) Maximize The Cut Segments
(14) Longest Common Subsequence
(15) Longest Repeated Subsequence
(16) Longest Increasing Subsequence
(17) Space Optimized Solution of LCS
(18) LCS (Longest Common Subsequence) of three strings
(19) Maximum Sum Increasing Subsequence
(20) Count all subsequences having product less than K
(21) Longest subsequence such that difference between adjacent is one
(22) Maximum subsequence sum such that no three are consecutive
(23) Egg Dropping Problem
(24) Maximum Length Chain of Pairs
(25) Maximum size square sub-matrix with all 1s
(26) Maximum sum of pairs with specific difference
(27) Min Cost PathProblem
(28) Maximum difference of zeros and ones in binary string
(29) Minimum number of jumps to reach end
(30) Minimum cost to fill given weight in a bag
(31) Minimum removals from array to make max –min <= K
(32) Longest Common Substring
(33) Count number of ways to reacha given score in a game
(34) Count Balanced Binary Trees of Height h
(35) LargestSum Contiguous Subarray [V>V>V>V IMP ]
(36) Smallest sum contiguous subarray
(37) Unbounded Knapsack (Repetition of items allowed)
(38) Word Break Problem
(39) Largest Independent Set Problem
(40) Partition problem
(41) Longest Palindromic Subsequence
(42) Count All Palindromic Subsequence in a given String
(43) Longest Palindromic Substring
(44) Longest alternating subsequence
(45) Weighted Job Scheduling
(46) Coin game winner where every player has three choices
(47) Count Derangements (Permutation such that no element appears in its original position) [ IMPORTANT ]
(48) Maximum profit by buying and selling a share at most twice [ IMP ]
(49) Optimal Strategy for a Game
(50) Optimal Binary Search Tree
(51) Palindrome PartitioningProblem
(52) Word Wrap Problem
(53) Mobile Numeric Keypad Problem [ IMP ]
(54) Boolean Parenthesization Problem
(55) Largest rectangular sub-matrix whose sum is 0
(56) Largest area rectangular sub-matrix with equal number of 1’s and 0’s [ IMP ]
(57) Maximum sum rectangle in a 2D matrix
(58) Maximum profit by buying and selling a share at most k times
(59) Find if a string is interleaved of two other strings
(60) Maximum Length of Pair Chain
Bit Manipulation
(1) Count set bits in an integer
(2) Find the two non-repeating elements in an array of repeating elements
(3) Count number of bits to be flipped to convert A to B
(4) Count total set bits in all numbers from 1 to n
(5) Program to find whether a no is power of two
(6) Find position of the only set bit
(7) Copy set bits in a range
(8) Divide two integers without using multiplication, division and mod operator
(9) Calculate square of a number without using *, / and pow()
(10) Power Set