500 Codes
500 Codes
Array
1.Find pair with given sum in the array
8.Find maximum length sub-array having equal number of 0’s and 1’s
9.Sort an array containing 0’s, 1’s and 2’s (Dutch national flag problem)
19.Replace each element of array with product of every other element without
using / operator
21.Find maximum difference between two elements in the array by satisfying given
constraints
30.Find the length of smallest subarray whose sum of elements is greater than the
given number
32.Find the smallest window in array sorting which will make the entire array
sorted
34.Maximum profit earned by buying and selling shares any number of times
40.Find minimum platforms needed in the station so to avoid any delay in arrival of
any train
44.Length of longest continuous sequence with same sum in given binary arrays
45.Rearrange array such that A[A[i]] is set to i for every element A[i]
49.Find pairs with given difference k in the array | Constant space solution
53.Find two odd occurring element in an array without using any extra space
54.Quickselect Algorithm
58.Replace each element of the array by its corresponding rank in the array
59.Print all Triplets in an array with sum less than or equal to given number
61.Find minimum difference between index of two given elements present in the array
77.Replace every element of an array with the least greater element on its right
78.Find all odd occurring elements in an array having limited range of elements
100.Find smallest range with at-least one element from each of the given lists
105.Merge Sort
106.Quicksort
108.Hybrid QuickSort
113.Custom Sort | Sort elements of the array by order of elements defined by the
second array
114.Inversion Count of an array
116.Binary Search
118.Interpolation search
119.Exponential search
134.Partition problem
137.Rod Cutting
139.Coin Change Problem (Total number of ways to get the denomination of coins)
142.Decode the given sequence to construct minimum number without repeated digits
143.All combinations of elements satisfying given constraints
Backtracking
1.Print all possible solutions to N Queens problem
5.Find path from source to destination in a matrix that satisfies given constraints
11.Find all binary strings that can be formed from given wildcard pattern
13.Magnet Puzzle
Binary
1.Bit Hacks — Part 1 (Basic)
18.Find two odd occurring element in an array without using any extra space
36.Huffman Coding
37.Find all odd occurring elements in an array having limited range of elements
Binary Tree
1.Check if two given binary trees are identical or not | Iterative & Recursive
14.Find next node in same level for given node in a binary tree
25.Check if binary tree can be converted to another by doing any no. of swaps of
left & right child
27.Print all paths from root to leaf nodes in given binary tree
38.Truncate given binary tree to remove nodes which lie on a path having sum less
than K
46.Print leaf to root path for every leaf node in a binary tree
50.Find all nodes at given distance from leaf nodes in a binary tree
52.Find Maximum Difference Between a Node and its Descendants in a Binary Tree
54.Calculate height of a binary tree with leaf nodes forming a circular doubly
linked list
BST
1.Insertion in BST
6.Check if given keys represents same BSTs or not without building the BST
8.Find Lowest Common Ancestor (LCA) of two nodes in a Binary Search Tree
13.Remove nodes from BST that have keys outside the valid range
16.Replace every element of an array with the least greater element on its right
20.Exponential search
21.Interpolation search
26.Quicksort Algorithm
28.Hybrid QuickSort
Dynamic Programming
1.Introduction to Dynamic Programming
17.Find size of largest square sub-matrix of 1’s present in given binary matrix
19.Find the minimum cost to reach last cell of the matrix from its first cell
21.Count number of paths in a matrix with given cost to reach destination cell
24.Partition problem
28.Rod Cutting
31.Coin Change Problem — Find total number of ways to get the denomination of coins
43.Find probability that a person is alive after taking N steps on the island
Graphs
1.Terminology and Representations of Graphs
10.Bipartite Graph
17.Total paths in given digraph from given source to destination having exactly m
edges
25.Check if given Graph is Strongly Connected or not using one DFS Traversal
Heap
1.Introduction to Priority Queues using Binary Heaps
4.Heap Sort
11.Find smallest range with at-least one element from each of the given lists
14.Huffman Coding
Linked List
1.Introduction to Linked Lists
8.Insert given node into the correct sorted position in the given sorted linked
list
9.Given a linked list, change it to be in sorted order
10.Split the nodes of the given linked list into front and back halves
12.Move front node of the given list to the front of the another list
14.Split given linked list into two lists where each list containing alternating
elements from it
23.Merge alternate nodes of two linked lists into the first list
35.Rearrange the linked list so that it has alternating high, low values
36.Rearrange a Linked List by Separating Odd Nodes from the Even Ones
37.Calculate height of a binary tree with leaf nodes forming a circular doubly
linked list
Matrix
1.Print Matrix in Spiral Order
4.Find Shortest path from source to destination in a matrix that satisfies given
constraints
5.Change all elements of row i and column j in a matrix to 0 if cell (i, j) has
value 0
11.Report all occurrences of an element in row wise and column wise sorted matrix
in linear time
15.Find probability that a person is alive after taking N steps on the island
29.Count number of paths in a matrix with given cost to reach destination cell
31.Find the minimum cost to reach last cell of the matrix from its first cell
33.Find size of largest square sub-matrix of 1’s present in given binary matrix
41.Find the maximum value of M[c][d] — M[a][b] over all choices of indexes
Queue
1.Queue Implementation
8.Find Shortest path from source to destination in a matrix that satisfies given
constraints
17.Find next node in same level for given node in a binary tree
Sorting
1.Insertion sort | Iterative & Recursive
6.Quicksort Algorithm
8.Hybrid QuickSort
14.Custom Sort | Sort elements of the array by order of elements defined by the
second array
18.Find the smallest window in array sorting which will make the entire array
sorted
27.Heap Sort
33.Sort an array containing 0’s, 1’s and 2’s (Dutch national flag problem)
Stack
1.Stack Implementation
6.Decode the given sequence to construct minimum number without repeated digits
11.Check if two given binary trees are identical or not | Iterative & Recursive
13.Find all binary strings that can be formed from given wildcard pattern
17.Print leaf to root path for every leaf node in a binary tree
String
1.Check if given string is a rotated palindrome or not
4.Check if strings can be derived from each other by circularly rotating them
8.Find all binary strings that can be formed from given wildcard pattern
9.Find all interleavings of given strings
10.Isomorphic Strings
13.Find all possible combinations by replacing given digits with characters of the
corresponding list
14.Find all words from given list that follows same order of characters as given
pattern
18.Inplace remove all occurrences of ‘AB’ and ‘C’ from the string
23.Validate an IP address
27.Find the longest substring of given string containing all distinct characters
34.Find all N-digit strictly increasing numbers (Bottom-Up and Top-Down Approach)
35.Find all N-digit binary numbers having more 1’s than 0’s for any prefix
43.Find all N-digit binary numbers with equal sum of bits in its two halves
54.Find the minimum number of inversions needed to make the given expression
balanced
58.Print all combinations of phrases that can be formed by picking words from each
of the given lists
Trie
1.Trie Implementation | Insert, Search and Delete
2.Memory efficient Trie Implementation using Map | Insert, Search and Delete
2.Huffman Coding
Puzzles
1.Clock angle problem — Find angle between hour and minute hand
8.Find maximum, minimum of three numbers without using conditional statement and
ternary operator | 4 methods
9.Find numbers represented as sum of two cubes for two different pairs
26.Determine if two integers are equal without using comparison and arithmetic
operators
30.Magnet Puzzle