Striver's A2Z DSA Sheet
Beginner Problems
- Pattern 1
- Pattern 2
- Pattern 3
- Pattern 4
- Pattern 5
- Pattern 6
- Pattern 7
- Pattern 8
- Pattern 9
- Pattern 10
- Pattern 11
- Pattern 12
- Pattern 13
- Pattern 14
- Pattern 15
- Pattern 16
- Pattern 17
- Pattern 18
- Pattern 19
- Pattern 20
- Pattern 21
- Pattern 22
- Count all Digits of a Number
- Count number of odd digits in a number
- Reverse a number
- Palindrome Number
- Return the Largest Digit in a Number
- Factorial of a given number
- Check if the Number is Armstrong
- Check for Perfect Number
- Check for Prime Number
- Count of Prime Numbers till N
- GCD of Two Numbers
- LCM of two numbers
- Divisors of a Number
- Sum of Array Elements
- Count of odd numbers in Array
- Check if the Array is Sorted I
- Reverse an array
- Highest Occurring Element in an Array
- Second Highest Occurring Element
- Sum of Highest and Lowest Frequency
- Reverse a String II
- Palindrome Check
- Largest Odd Number in a String
- Longest Common Prefix
- Isomorphic Strings
- Rotate String
- Valid Anagram
- Sort Characters by Frequency
- Sum of First N Numbers
- Factorial of a Given Number
- Sum of Array Elements II
- Reverse a String I
- Check if String is Palindrome or Not
- Check if a Number is Prime or Not
- Reverse an array 2
- Check if the Array is Sorted II
- Sum of Digits in a Given Number
- Fibonacci Number
Sorting
- Selection Sort
- Bubble Sort
- Insertion Sorting
- Merge Sorting
- Quick Sorting
Arrays
- Linear Search
- Largest Element
- Second Largest Element
- Maximum Consecutive Ones
- Left Rotate Array by One
- Left Rotate Array by K Places
- Move Zeros to End
- Remove duplicates from sorted array
- Find missing number
- Union of two sorted arrays
- Intersection of two sorted arrays
- Majority Element-I
- Leaders in an Array
- Rearrange array elements by sign
- Print the matrix in spiral manner
- Pascal's Triangle I
- Pascal's Triangle II
- Pascal's Triangle III
- Rotate matrix by 90 degrees
- Set Matrix Zeroes
- Two Sum
- 3 Sum
- 4 Sum
- Sort an array of 0's 1's and 2's
- Kadane's Algorithm
- Next Permutation
- Majority Element-II
- Find the repeating and missing number
- Count Inversions
- Reverse Pairs
- Maximum Product Subarray in an Array
- Merge two sorted arrays without extra space
Hashing
- Longest Consecutive Sequence in an Array
- Longest Subarray with given Sum K (Positives)
- Longest Subarray with sum K (Positives + Negatives)
- Count Subarrays with given XOR K
- Count Subarrays with given sum
Binary Search
- Binary Search to find X in sorted array
- Lower Bound
- Upper Bound
- Search insert position
- Floor and Ceil in Sorted Array
- First and last occurrence
- Search in rotated sorted array-I
- Search in rotated sorted array-II
- Find minimum in Rotated Sorted Array
- Find out how many times the array is rotated
- Single element in sorted array
- Find square root of a number
- Find Nth root of a number
- Find the smallest divisor
- Koko eating bananas
- Minimum days to make M bouquets
- Capacity to Ship Packages Within D Days
- Kth Missing Positive Number
- Painter's Partition
- Aggressive Cows
- Book Allocation Problem
- Find peak element
- Median of 2 sorted arrays
- Kth element of 2 sorted arrays
- Minimize Max Distance to Gas Station
- Split array - largest sum
- Find row with maximum 1's
- Search in a 2D Matrix
- Search in 2D matrix - II
- Find Peak Element - II
- Matrix Median
Recursion
- Pow(x,n)
- Generate Parentheses
- Power Set
- Check if there exists a subsequence with sum K
- Count all subsequences with sum K
- Combination Sum
- Combination Sum II
- Subsets I
- Subsets II
- Combination Sum III
- Letter Combinations of a Phone Number
- Palindrome partitioning
- Word Search
- N Queen
- Rat in a Maze
- M Coloring Problem
- Sudoku Solver
Linked-List
- Traversal in Linked List
- Deletion of the head of LL
- Deletion of the tail of Linked List
- Deletion of the Kth element of Linked List
- Delete the element with value X
- Insertion at the head of Linked List
- Insertion at the tail of Linked List
- Insertion at the Kth position of Linked List
- Insertion before the value X in Linked List
- Convert Array to Doubly Linked List
- Delete Tail of Doubly Linked List
- Delete Kth Element of Doubly Linked List
- Removing given node in Doubly Linked List
- Insert node before head in Doubly Linked List
- Insert node before tail in Doubly Linked List
- Insert node before (kth node) in Doubly Linked List
- Insert before given node in Doubly Linked List
- Add two numbers in Linked List
- Segregate odd and even nodes in Linked List
- Sort a Linked List of 0's 1's and 2's
- Remove Nth node from the back of the LL
- Reverse a LL
- Add one to a number represented by LL
- Find Middle of Linked List
- Delete the middle node in LL
- Check if LL is palindrome or not
- Find the intersection point of Y LL
- Detect a loop in LL
- Find the starting point in LL
- Length of loop in LL
- Reverse a Doubly Linked List
- Find pairs with given sum in DLL
- Remove duplicates from sorted DLL
- Delete all occurrences of a key in DLL
- Flattening of a Linked List
- Clone a Linked List with random and next pointer
- Sort a LL
- Delete Node in a Linked List
- Rotate a LL
Bit Manipulation
- Introduction to Bit Manipulation
- Check if the i-th bit is set or not
- Check if a number is odd or not
- Check if a number is power of 2 or not
- Count the number of set bits
- Set/Unset the rightmost unset bit
- Swap two numbers
Greedy Algorithms
- Assign Cookies
- Fractional Knapsack
- Greedy algorithm to find minimum number of coins
- Lemonade Change
- Valid Parenthesis String
- N meetings in one room
- Jump Game
- Jump Game II
- Minimum number of platforms required for a railway
- Job sequencing Problem
- Candy
- Program for Shortest Job First (SJF) CPU Scheduling
- Program for Least Recently Used (LRU) Page Replacement Algorithm
- Insert Interval
Sliding Window / 2 Pointer
- Longest Substring Without Repeating Characters
- Max Consecutive Ones III
- Fruit Into Baskets
- Longest Repeating Character Replacement
- Binary Subarrays With Sum
- Count Number of Nice Subarrays
- Number of Substrings Containing All Three Characters
- Maximum Points You Can Obtain from Cards
- Longest Substring with At Most K Distinct Characters
- Subarray with k different integers
- Minimum Window Substring
Stack / Queues
- Implement Stack using Arrays
- Implement Queue using Arrays
- Implement Stack using Queue
- Implement Queue using Stack
- Implement stack using Linkedlist
- Implement queue using Linkedlist
- Check for balanced parentheses
- Implement Min Stack
- Infix to Postfix Conversion using Stack
- Prefix to Infix Conversion
- Prefix to Postfix Conversion
- Postfix to Prefix Conversion
- Postfix to Infix
- Infix to Prefix Conversion
- Next Greater Element
- Next Greater Element II
- Next Smaller Element
- Number of NGEs to the right
- Trapping Rainwater
- Sum of subarray minimum
- Asteroid Collision
- Sum of subarray ranges
Binary Trees
- Introduction to Trees
- Binary Tree Representation in C++
- Binary Tree Representation in Java
- Binary Tree Traversals in Binary Tree
- Preorder Traversal of Binary Tree
- Inorder Traversal of Binary Tree
- Postorder Traversal of Binary Tree
- Level order Traversal / Level order traversal in spiral form
- Iterative Preorder Traversal of Binary Tree
- Iterative Inorder Traversal of Binary Tree
- Postorder Traversal of Binary Tree using 2 stack
- Postorder Traversal of Binary Tree using 1 stack
- Preorder, Inorder, and Postorder Traversal in one Traversal
- Height of a Binary Tree
- Check if the Binary tree is height-balanced or not
- Diameter of Binary Tree
- Maximum Path Sum
- Check if two trees are identical or not
- Zig Zag Traversal of Binary Tree
- Boundary Traversal of Binary Tree
- Vertical Order Traversal of Binary Tree
- Top View of Binary Tree
- Bottom View of Binary Tree
- Right/Left View of Binary Tree
- Symmetric Binary Tree
- Root to Node Path in Binary Tree
- LCA in Binary Tree
- Maximum Width of Binary Tree
- Check for Children Sum Property
- Print all the Nodes at a distance of K in Binary Tree
- Count total Nodes in a Complete Binary Tree
Binary Search Trees
- Introduction to Binary Search Tree
- Search in a Binary Search Tree
- Find Min/Max in BST
- Ceil in a Binary Search Tree
- Floor in a Binary Search Tree
- Insert a given Node in Binary Search Tree
- Delete a Node in Binary Search Tree
- Find K-th smallest/largest element in BST
- Check if a tree is a BST or not
- LCA in Binary Search Tree
- Construct a BST from a preorder traversal
- Inorder Successor/Predecessor in BST
- Merge 2 BST's
- Two Sum In BST
- Recover BST
- Largest BST in Binary Tree
Heaps
- Introduction to Priority Queues using Binary Heaps
- Min Heap and Max Heap Implementation
- Check if an array represents a min-heap or not
- Convert min Heap to max Heap
- Kth largest element in an array
- Kth smallest element in an array
- Sort K sorted array
- Merge M sorted Lists
- Replace each array element by its corresponding rank
Graphs
- Graph and Types
- Graph Representation
- Connected Components
- BFS
- DFS
- Number of provinces
- Connected Components Problem in Matrix
- Rotten Oranges
- Flood fill
- Cycle Detection in Undirected Graph (BFS)
- Cycle Detection in Undirected Graph (DFS)
- 0/1 Matrix (Bfs Problem)
- Surrounded Regions
- Number of Enclaves
- Word ladder - 1
- Word ladder - 2
- Number of Distinct Islands
- Bipartite Graph (BFS)
- Bipartite Graph (DFS)
- Cycle Detection in Directed Graph (DFS)
- Topo Sort
- Kahn's Algorithm
- Cycle Detection in Directed Graph (BFS)
- Course Schedule - I
- Course Schedule - II
- Find Eventual Safe States
- Alien Dictionary
- Shortest Path in UG with unit weights
- Shortest Path in DAG
- Dijkstra's Algorithm
- Floyd warshall algorithm
- Find the city with the smallest number of neighbors
- Disjoint Set
- Find the MST weight
- Number of operations to make network connected
- Accounts merge
- Number of islands II
- Making a large island
- Most stones removed with same row or column
- Kosaraju's algorithm
- Bridges in graph
- Articulation point in graph
Dynamic Programming
- Climbing stairs
- Frog Jump
- Frog jump with K distances
- Maximum sum of non adjacent elements
- House robber
- Ninja's training
- Grid unique paths
- Unique paths II
- Minimum Falling Path Sum
- Triangle
- Cherry pickup II
- Best time to buy and sell stock
- Best time to buy and sell stock II
- Best time to buy and sell stock III
- Best time to buy and sell stock IV
- Best time to buy and sell stock with transaction fees
- Subset sum equals to target
- Partition equal subset sum
- Partition a set into two subsets with minimum absolute sum difference
- Count subsets with sum K
- Count partitions with given difference
- 0 and 1 Knapsack
- Minimum coins
- Target sum
- Coin change II
- Unbounded knapsack
- Rod cutting problem
- Longest Increasing Subsequence
- Print Longest Increasing Subsequence
- Largest Divisible Subset
- Longest String Chain
- Longest Bitonic Subsequence
- Number of Longest Increasing Subsequences
- Longest common subsequence
- Longest common substring
- Longest palindromic subsequence
- Minimum insertions to make string palindrome
- Minimum insertions or deletions to convert string A to B
- Shortest common supersequence
- Distinct subsequences
- Edit distance
- Wildcard matching
- Matrix chain multiplication
- Burst balloons
- Palindrome partitioning II
- Partition Array for Maximum Sum
- Different Ways to Evaluate a Boolean Expression
Tries
- Trie Implementation and Operations
- Trie Implementation and Advanced Operations
- Longest Word with All Prefixes
- Number of distinct substrings in a string
- Maximum XOR of two numbers in an array
- Maximum Xor with an element from an array
Strings (Advanced Algo)
- Reverse every word in a string
- Minimum number of bracket reversals to make an expression balanced
- Count and say
- Rabin Karp Algorithm
- Z function
- KMP Algorithm or LPS array
- Shortest Palindrome
- Longest happy prefix
Maths
- Print all primes till N
- Prime factorisation of a Number
- Count primes in range L to R
SOURCE: takeuforward