archgaelix
Uses
Archive
DSA 450 [42/413]
Reverse an array
#array
Find the maximum and minimum element in an array
#array
Find the Kth max and min element in an array
#array
#heap
Sort an array of 0s, 1s and 2s
#array
Move all the negative elements to one side of the array
#array
Find the union and intersection of the two sorted arrays
#array
Cyclically rotate an array by one
#array
Minimise the maximum difference between heights
#array
Minimum number of jumps to reach end of an array
#array
Find the duplicate in an array of N+1 integers
#array
Kadane’s algorithm
#array
#dp
Merge intervals
#array
Next permutation
#array
Count inversion
#array
#search-sort
Best time to buy and sell stock
#array
Find all pairs on integer array whose sum is equal to K
#array
Find common elements in 3 sorted arrays
#array
Rearrange the array in alternating positive and negative items with O(1) extra space
#array
Find if there is any subarray with sum equal to 0
#array
Find factorial of a large number
#array
Find maximum product subarray
#array
Find longest consecutive subsequence
#array
Given an array of size N and a number K, find all elements that appear more than N/K times
#array
Find whether an array is a subset of another array
#array
Find the triplet that sum to a given value
#array
Trapping rain water
#array
Chocolate distribution
#array
#greedy
Smallest subarray with sum greater than a given value
#array
Three way partitioning of an array around a given value
#array
Minimum swaps required to bring elements <= K together
#array
Minimum number of merge operations required to make an array palindrome
#array
Median of 2 sorted arrays of equal size
#array
Median of 2 sorted arrays of different size
#array
Spiral traversal on a matrix
#matrix
Search an element in a matrix
#matrix
Find median in a row wise sorted matrix
#matrix
Find row with maximum number of 1s
#matrix
Print elements in sorted order using row-column wise sorted matrix
#matrix
Maximum size rectangle
#matrix
Find a specific pair in matrix
#matrix
Rotate matrix by 90 degrees
#matrix
Kth smallest element in a row-column wise sorted matrix
#matrix
Common elements in all rows of a given matrix
#matrix
Check whether a string is palindrome
#string
Find duplicate characters in a string
#string
Why are strings immutable in Java?
#string
Check whether one string is a rotation of another
#string
Check whether a string is a valid shuffle of two strings
#string
Count and say
#string
Find the longest palindrome in a string
#string
Print all subsequences of a string
#string
Split the binary string into two substring with equal 0s and 1s
#string
Word wrap
#string
#dp
Edit distance
#string
#dp
Find next greater number with same set of digits
#string
Balanced parenthesis
#string
#st-q
Word break
#string
#trie
#backtracking
#dp
Rabin Karp algorithm
#string
KMP algorithm
#string
Bayer Moore algorithm
#string
Convert a sentence into its equivalent mobile numeric keypad sequence
#string
Minimum number of bracket reversals needed to make an expression balanced
#string
Count all palindromic subsequence in a given string
#string
#dp
Count of number of given string in 2D character array
#string
Search a word in a 2D grid of characters
#string
Converting roman numerals to decimal
#string
Longest common prefix
#string
Number of flips to make binary string alternate
#string
Find the second most repeated word in string
#string
Minimum number of swaps for bracket balancing
#string
Program to generate all possible valid IP addresses from given string
#string
Find the smallest window that contains all characters of string itself
#string
Rearrange characters in a string such that no two adjacent are same
#string
#heap
#greedy
Minimum characters to be added at front to make string palindrome
#string
Given a sequence of words, print all anagrams together
#string
#trie
#greedy
Find the smallest window in a string containing all characters of another string
#string
Recursively remove all adjacent duplicates
#string
String matching where one string contains wildcard characters
#string
Function to find number of customers who could not get a computer
#string
Transform one string to another using minimum number of given operation
#string
Check if two given strings are isomorphic to each other
#string
Recursively print all sentences that can be formed from list of word lists
#string
Find first and last positions of an element in a sorted array
#search-sort
Find a fixed point (value equal to index) in a given array
#search-sort
Search in a rotated sorted array
#search-sort
Square root of an integer
#search-sort
Maximum and minimum of an array using minimum number of comparisons
#search-sort
Optimum location of point to minimize total distance
#search-sort
Find missing and repeating
#search-sort
Find majority element
#search-sort
Searching in an array where adjacent differ by at most K
#search-sort
Find a pair with a given difference
#search-sort
Find four elements that sum to a given value
#search-sort
Maximum sum such that no 2 elements are adjacent
#search-sort
Count triplet with sum smaller than a given value
#search-sort
Merge 2 sorted arrays
#array
#search-sort
Print all subarrays with 0 sum
#search-sort
Product array puzzle
#search-sort
Sort array according to count of set bits
#search-sort
Minimum number of swaps required to sort the array
#search-sort
Bishu and soldiers
#search-sort
Rasta and Kheshtak
#search-sort
Kth smallest number again
#search-sort
Find pivot element in a sorted array
#search-sort
Kth element of two sorted arrays
#search-sort
Aggressive cows
#search-sort
Book allocation aka Painter’s Partition
#search-sort
Ekospoj
#search-sort
Job scheduling algorithm
#search-sort
Missing number in AP
#search-sort
Smallest number with atleast N trailing zeroes in factorial
#search-sort
Roti Prata
#search-sort
Doublehelix
#search-sort
Subset sums
#search-sort
Implement merge-sort in-place
#search-sort
Partitioning and sorting arrays with many repeated entries
#search-sort
Reverse a linked list
#ll
Reverse a linked list in group of given size
#ll
Detect loop in a linked list
#ll
Delete loop in a linked list
#ll
Find the starting point of the loop
#ll
Remove duplicates in a sorted linked list
#ll
Remove duplicates in a unsorted linked list
#ll
Move the last element to front in a linked list
#ll
Add 1 to a number represented as a linked list
#ll
Add two numbers represented by linked lists
#ll
Intersection of two sorted linked list
#ll
Intersection point of two linked lists
#ll
Merge sort for linked lists
#ll
Quicksort for linked lists
#ll
Find the middle element of a linked list
#ll
Check if a linked list is a circular linked list
#ll
Split a circular linked list into two halves
#ll
Check whether the singly linked list is a palindrome
#ll
Deletion from a circular linked list
#ll
Reverse a doubly linked list
#ll
Find pairs with a given sum in a DLL
#ll
Count triplets in a sorted DLL whose sum is equal to given value X
#ll
Sort a K sorted doubly linked list
#ll
Rotate DLL by N nodes
#ll
Rotate a doubly linked list in group of given size
#ll
Can we reverse a linked list in less than O(n)?
#ll
Why is quicksort preferred for arrays while merge sort for linked lists?
#ll
Flatten a linked list
#ll
Sort a ll of 0s, 1s and 2s
#ll
Clone a linked list with next and random pointer
#ll
Multiply 2 numbers represented by ll
#ll
Delete nodes which have a greater value on right side
#ll
Segregate even and odd nodes in a linked list
#ll
Program for Nth node from the end of a linked list
#ll
Find the first non-repeating character from a stream of characters
#ll
Level order traversal
#bt
Reverse level order traversal
#bt
Height of a tree
#bt
Diameter of a tree
#bt
Mirror of a tree
#bt
Inorder traversal of a tree
#bt
Preorder traversal of a tree
#bt
Postorder traversal of a tree
#bt
Right view of a tree
#bt
Left view of a tree
#bt
Top view of a tree
#bt
Bottom view of a tree
#bt
Zig-zag traversal of a binary tree
#bt
Check if a tree is balanced
#bt
Diagonal traversal of a binary tree
#bt
Boundary traversal of a binary tree
#bt
Construct binary tree from string with bracket representation
#bt
Convert binary tree into doubly linked list
#bt
Convert binary tree into sum tree
#bt
Construct binary tree from inorder and preorder traversal
#bt
Find minimum swaps required to convert a binary tree into BST
#bt
Check if binary tree is sum tree
#bt
Check if all leaf nodes are at same level
#bt
Check if a binary tree contains duplicate subtrees of size 2 or more
#bt
Check if 2 trees are mirror
#bt
Sum of nodes on the longest path from root to leaf node
#bt
Check if given graph is tree
#bt
Find largest subtree sum in a tree
#bt
Maximum sum of nodes in binary tree such that no two are adjacent
#bt
Print all K sum paths in a binary tree
#bt
Find LCA in a binary tree
#bt
Find distance between 2 nodes in a binary tree
#bt
Kth ancestor of node in a binary tree
#bt
Find all duplicate subtrees in a binary tree
#bt
Tree isomorphism
#bt
Find a value in a BST
#bst
Find min and max value in a BST
#bst
Find inorder successor and inorder predecessor in a BST
#bst
Deletion of a node in a BST
#bst
Check if a tree is a BST
#bst
Populate inorder successor of all nodes
#bst
Find LCA in a BST
#bst
Construct BST from preorder traversal
#bst
Convert binary tree into BST
#bst
Convert a normal BST into a balanced BST
#bst
Merge two BST
#bst
Find Kth largest element in a BST
#bst
Find Kth smallest element in a BST
#bst
Count pairs from 2 BST whose sum is equal to given value X
#bst
Find the median of BST in O(n) time and O(1) space
#bst
Count BST nodes that lie in a given range
#bst
Replace every element with the least greater element on its right
#bst
Given N appointments, find the conflicting appointments
#bst
Check preorder is valid
#bst
Check whether BST contains dead end
#bst
Largest BST in a binary tree
#bst
Flatten BST to sorted list
#bst
Activity selection
#greedy
Job sequencing
#greedy
Huffman coding
#greedy
Water connection
#greedy
Fractional knapsack
#greedy
Find minimum number of coins
#greedy
Maximum trains for which stoppage can be provided
#greedy
Minimum platforms
#greedy
Buy maximum stocks if I stocks can be bought on Ith day
#greedy
Find the minimum and maximum amount to buy all N candies
#greedy
Minimum cost to cut a board into squares
#greedy
Check if it is possible to survive on island
#greedy
Find maximum meetings in one room
#greedy
Maximum product subset of an array
#greedy
Maximize array sum after K negations
#greedy
Maximize the sum of arr[i]*i
#greedy
Maximum sum of absolute difference of an array
#greedy
Maximize sum of consecutive differences in a circular array
#greedy
Minimum sum of absolute difference of pairs of two arrays
#greedy
Shortest Job First (SJF) CPU scheduling
#greedy
Least Recently Used (LRU) page replacement algorithm
#greedy
Smallest subset with sum greater than all other elements
#greedy
Defense of a kingdom
#greedy
Die hard
#greedy
Wine trading in Gergovia
#greedy
Picking up chicks
#greedy
Chocolate
#greedy
Arranging amplifiers
#greedy
K centers
#greedy
Find smallest number with given number of digits and sum of digits
#greedy
Find maximum sum possible equal sum of three stacks
#greedy
Rat in a maze
#graph
#backtracking
Printing all solutions to N-queens
#backtracking
Remove invalid parentheses
#backtracking
Sudoku solver
#backtracking
M coloring
#graph
#backtracking
Print all palindromic partitions of a string
#backtracking
Knight’s tour
#backtracking
Tug of war
#backtracking
Find shortest safe route in a path with landmines
#backtracking
Combination sum
#backtracking
Find maximum number possible by doing atmost K swaps
#backtracking
Print all permutations of a string
#string
#backtracking
Longest possible route in a matrix with hurdles
#backtracking
Print all possible paths from top left to bottom right of a MxN matrix
#backtracking
Partition a set into K subsets with equal sum
#backtracking
Find the Kth permutation sequence of first N natural numbers
#backtracking
Implement stack from scratch
#st-q
Implement queue from scratch
#st-q
Implement 2 stack in an array
#st-q
Find the middle element of a stack
#st-q
Implement N stacks in an array
#st-q
Reverse a string using stack
#st-q
Design a stack that supports getmin() in O(1) time and O(1) extra space
#st-q
Find the next greater element
#st-q
Celebrity
#st-q
Arithmetic expression evaluation
#st-q
Evaluation of postfix expression
#st-q
Implement a method to insert an element at its bottom without using any other data structure
#st-q
Reverse a stack using recursion
#st-q
Sort a stack using recursion
#st-q
Merge overlapping intervals
#st-q
Largest rectangular area in histogram
#st-q
Length of the longest valid substring
#st-q
Expression contains redundant bracket
#st-q
Implement stack using queue
#st-q
Implement stack using deque
#st-q
Stack permutations
#st-q
Implement queue using stack
#st-q
Implement N queue in an array
#st-q
Implement a circular queue
#st-q
LRU cache implementation
#st-q
Reverse a queue using recursion
#st-q
Reverse the first K elements of a queue
#st-q
Interleave the first half of the queue with second half
#st-q
Find the first circular tour that visits all petrol pumps
#st-q
Minimum time required to rot all oranges
#st-q
Distance of nearest cell having 1 in a binary matrix
#st-q
First negative integer in every window of size K
#st-q
Check if all levels of two trees are anagrams
#st-q
Sum of minimum and maximum elements of all subarrays of size K
#st-q
Minimum sum of squares of character counts in a given string after removing K characters
#st-q
Next smaller element
#st-q
Implement a maxheap/minheap
#heap
Heap sort
#heap
Maximum of all subarrays of size K
#heap
Kth largest element in an array
#heap
Merge K sorted arrays
#heap
Merge 2 binary max heaps
#heap
Kth largest sum continuous subarrays
#heap
Reorganize strings
#heap
Merge K sorted linked lists
#ll
#heap
Smallest range in K lists
#heap
Median in a stream of integers
#heap
Check if a binary tree is heap
#heap
Connect N ropes with minimum cost
#heap
#greedy
Convert BST to min heap
#heap
Convert min heap to max heap
#heap
Minimum sum of two numbers formed from digits of an array
#heap
Create and print a graph
#graph
Implement BFS
#graph
Implement DFS
#graph
Detect cycle in directed graph using BFS/DFS
#graph
Detect cycle in undirected graph using BFS/DFS
#graph
Minimum steps by knight
#graph
Flood fill algorithm
#graph
Clone a graph
#graph
Making wired connections
#graph
Word ladder
#graph
Dijkstra algorithm
#graph
Implement topological sort
#graph
Minimum time taken by each job to be completed given by a directed acyclic graph
#graph
Find whether it is possible to finish all tasks from given dependencies
#graph
Find the number of islands
#graph
Given a sorted dictionary of an alien language, find order of characters
#graph
Implement Kruskal’s algorithm
#graph
Implement Prim’s algorithm
#graph
Total number of spanning tree in a graph
#graph
Implement Bellman Ford algorithm
#graph
Implement Floyd Warshall algorithm
#graph
Travelling salesman
#graph
Graph colouring
#graph
Snake and ladders
#graph
Find bridge in a graph
#graph
Count strongly connected components (Kosaraju algorithm)
#graph
Check if graph is bipartite
#graph
Detect negative cycle in a graph
#graph
Longest path in a directed acyclic graph
#graph
Journey to the moon
#graph
Cheapest flights within K stops
#graph
Oliver and the game
#graph
Water jug using BFS
#graph
Minimum edges to reverse to make path from source to destination
#graph
Paths to travel each nodes using each edge
#graph
Vertex cover
#graph
Chinese postman or route inspection
#graph
Number of triangles in a directed and undirected graph
#graph
Minimise the cashflow in a set of friends
#graph
#greedy
Two clique
#graph
Construct a trie from scratch
#trie
Find shortest unique prefix for every word in a given list
#trie
Implement a phone directory
#trie
Print unique rows in a given boolean matrix
#trie
Coin change
#dp
Knapsack
#dp
Binomial coefficient
#dp
Permutation coefficient
#dp
Nth catalan number
#dp
Matrix chain multiplication
#dp
Subset sum aka Partitions
#dp
#backtracking
Friends pairing
#dp
Gold mine
#dp
Assembly line scheduling
#dp
Painting the fence
#dp
Maximize the cut segments
#dp
Longest common subsequence
#string
#dp
Longest repeated subsequence
#string
#dp
Longest increasing subsequence
#dp
Space optimized solution of LCS
#dp
LCS of three strings
#dp
Maximum sum increasing subsequence
#dp
Count all subsequences having product less than K
#dp
Longest subsequence such that difference between adjacent is one
#dp
Maximum subsequence sum such that no three are consecutive
#dp
Egg dropping
#dp
Maximum length chain of pairs
#dp
Maximum size square sub-matrix with all 1s
#dp
Maximum sum of pairs with specific difference
#dp
Min cost path
#dp
Maximum difference of zeros and ones in binary string
#dp
Minimum cost to fill given weight in a bag
#dp
Minimum removals from array to make max - min <= K
#dp
Longest common substring
#dp
Count number of ways to reach a given score in a game
#dp
Count balanced binary trees of height h
#dp
Smallest sum contiguous subarray
#dp
Unbounded knapsack
#dp
Largest independent set
#dp
Longest palindromic subsequence
#dp
Longest palindromic substring
#dp
Longest alternating subsequence
#dp
Weighted job scheduling
#dp
Coin game winner where every player has three choices
#dp
Count derangements
#dp
Optimal strategy for a game
#dp
Optimal binary search tree
#dp
Palindrome partitioning
#dp
Mobile numeric keypad
#dp
Boolean parenthesization
#dp
Largest rectangular sub-matrix whose sum is 0
#dp
Largest area rectangular sub-matrix with equal number of 1s and 0s
#dp
Maximum sum rectangle in a 2D matrix
#dp
Maximum profit by buying and selling a share at most K times
#dp
Find if a string is interleaved of two other strings
#dp
Maximum length of pair chain
#dp
Count set bits in an integer
#bit
Find the two non-repeating elements in an array of repeating elements
#bit
Count number of bits to be flipped to convert A to B
#bit
Count total set bits in all numbers from 1 to N
#bit
Check if a number is a power of 2
#bit
Find position of the only set bit
#bit
Copy set bits in a range
#bit
Divide two integers without using multiplication, division or mod operator
#bit
Calculate square of a number without using *, / and pow()
#bit
Power set
#bit