Data Structures and Algorithms Practice Problems
Published in
7 min readNov 23, 2021
- Two Sum
- Zero Sum
- Zero Sum II
- Sort Binary Array
- Maximum Length Subarray
- Largest Subarray
- Maximum Product Pair
- Dutch National Flag Problem
- Merge Arrays
- Merge Arrays II
- Maximum Continuous Sequence
- Maximum Continuous Sequence II
- Equilibrium Index
- Largest Consecutive Subarray
- Majority Element
- Move Zeroes to End
- Replace Array Elements
- Replace Array Elements II
- Longest Bitonic Subarray
- Maximum Difference Pair
- Maximum Sum Subarray
- Maximum Sum Subarray II
- Maximum Sum Circular Subarray
- Rearrange Array
- Rearrange Array II
- Rearrange Array III
- Rearrange Array IV
- Rearrange Array V
- Sorted Merge Arrays
- Sorted Merge Arrays II
- Combinations
- Combinations II
- Combinations III
- Combinations IV
- Combinations V
- Combinations VI
- Combinations VII
- Combinations VIII
- Combinations IX
- Combinations X
- Combinations XI
- Subset Sum
- Ball Arrangements
- Minimum Sum Subarray
- Maximum Product Subarray
- K Sum Subarray
- K Sum Subarray II
- Smallest Subarray
- Smallest Window to Sort Array
- Maximum Path Sum
- Buy N Sell Shares
- Trapping Rain Water
- Minimum Platforms
- Decode Array
- Sort Array Single Swap
- 3 Sum
- 3 Sum II
- 3 Sum III
- Longest Continuous Sequence
- Reverse Consecutive Elements
- Maximum Product Subset
- 2 Diff
- 4 Sum
- Arithmetic Triplets
- Geometric Triplets
- Buy and Sell Stock
- Buy and Sell Stock II
- Buy and Sell Stock III
- Group Elements
- Minimum Absolute Difference
- Minimum Absolute Difference II
- Symmetric Pairs
- Closest Pair
- Partition Array Equal Sum
- Distinct Elements Count
- Maximum Sum Number
- Largest Distinct Subarrays
- Maximum Product Triplet
- Repeating Element Index
- Minimum Absolute Sum Pair
- Consecutive Numbers
- Non Overlapping Pairs
- Add Arrays
- Minimum Product Triplet
- Distinct Absolute Count
- Break Point Index
- Frequency Map
- Frequency Map II
- Sorted Triplet
- Shuffle Array
- Shuffle Array II
- Shuffle Array III
- Strictly Increasing Subarrays
- Duplicates in Range K
- Minimum Range
- Minimum Range II
- Longest Consecutive Subsequence
- Determine Index
- Minimum Moves to Convert Array
- Left Rotate Array
- Right Rotate Array
- Activity Selection Problem
- K Divisible Pairs
- Minimum Removals
- Two Sum II
- Greater Elements
- Sort Array
- Counting Sort
- Inversion Count
- Inversion Count II
- Sort by Frequency and Index
- Sort with Duplicates
- Largest Number
- Surpasser Count
- 3 Partition Problem
- 3 Partition Problem II
- K Partition Problem
- Minimum Merge Operations
- Coin Change Problem
- Coin Change Problem II
- Power Set
- Power Set II
- Missing Number
- Missing Number II
- Missing Number III
- Odd Occurring Element
- Odd Occurring Element II
- Odd Occurring Element III
- Odd Occurring Element IV
- Duplicate Element
- Duplicate Element II
- Missing and Duplicate Element
- Next Greater Element
- Next Greater Element II
- Previous Smaller Element
- Longest Increasing Subsequence
- Longest Increasing Subsequence II
- Merging Overlapping Intervals
- Maximum Overlapping Intervals
- Unattended Customers Count
- Minimum Number K Swaps
- Rod Cutting
- Rod Cutting II
- Shrink Array
- Ticket Itinerary
- Sort K Sorted Array
- Job Sequencing Problem
- Employees Manager Mapping
- Snake and Ladder Problem
- Spiral Matrix
- Spiral Matrix II
- Spiral Matrix III
- Shift Matrix
- Convert Matrix
- Convert Matrix II
- Diagonal Matrix Traversal
- Replace Matrix
- Replace Matrix II
- Rotate Matrix
- Rotate Matrix II
- Negative Numbers Count
- Search Matrix
- Search Matrix II
- Toeplitz Matrix
- Fill Matrix
- Common Elements
- Maximum Ones Row
- Largest Square Submatrix
- Largest Square Submatrix II
- Largest Rectangle Area
- Maximum Difference Pair II
- N Queen Problem
- Knight Tour Problem
- Chess Knight Problem
- Shortest Path
- Shortest Path II
- Shortest Path III
- Longest Path
- Matrix Path
- Matrix Path II
- Matrix Path III
- Matrix Path IV
- Matrix Path V
- Matrix Path VI
- Matrix Path VII
- Minimum Cost Path
- Minimum Cost Path II
- Longest Continuous Sequence II
- Longest Continuous Sequence III
- Collect Maximum Points
- Tiles Problem
- Largest Plus
- Collect Coins
- Duplicate Rows
- Boggle Search
- Submatrix Sum
- Maximum Sum Submatrix
- Maximum Sum Submatrix II
- Alive Probability
- Maximum Length Snake Sequence
- Flood Fill Algorithm
- Count Islands
- Construct Young Tableau
- Extract Min in Young Tableau
- Replace Element in Young Tableau
- Sort with Young Tableau
- Magnet Puzzle
- Rotated Palindrome
- Longest Palindromic Substring
- Repeated Subsequence
- Derive Strings
- Check Circular Moves
- Excel Sheet Column Name
- Check Anagram
- Interleaving String
- Interleaving String II
- Isomorphic Strings
- Palindromic Substrings
- Group Anagrams
- Transform String
- Transform String II
- Transform String III
- Balanced Expression
- Longest Palidromic Sum Substring
- Print String Zig Zag
- Run Length Encoding
- Longest Distinct Substring
- Longest Distinct Substring II
- Palindromic Permutations
- Anagram Substring
- Maximum Occurring Word
- Permutations
- Permutations II
- Next Permutations
- Lexical Minimal String Rotation
- Balanced Parentheses
- Duplicate Parenthesis
- Evaluate Postfix Expression
- Infix to Postfix
- Palindrome String
- Minimum Inversions
- Remove Adjacent Duplicates
- Remove Adjacent Duplicates II
- First Non Repeating Character
- Lexicographic Permutations
- Lexicographic Rank
- Decode Sequence
- K Distinct Substrings
- Pattern Match
- Pattern Match II
- Pattern Match III
- Pattern Match IV
- Pattern Match V
- Wildcard Pattern Matching
- Wildcard Pattern Matching II
- Longest Balanced Parenthesis
- Longest Palindrome
- Reverse Text
- N Digit Numbers
- N Digit Numbers II
- N Digit Numbers III
- N Digit Numbers IV
- N Digit Numbers V
- N Digit Numbers VI
- N Digit Numbers VII
- First K Non Repeating
- K Palindrome String
- Minimum Delete Operations
- Minimum Cut Palindromic Partition
- Lexicographic Sorting
- Shortest Unique Prefix
- Rearrange Words
- Turn off Kth Bit
- Turn on Kth Bit
- Is Kth Bit Set
- Toggle Kth Bit
- Unset Rightmost Set Bit
- Position of Rightmost Set Bit
- Count Set Bits
- Count Flipped Bits
- Next Power of 2
- Previous Power of 2
- Parity of Number
- Swap Bits
- Swap Bits II
- Power of 4
- Power of 8
- Reverse Bits
- Swap Adjacent Bits
- Adjacent Set Bits
- Decimal to Binary
- Add Binary
- Circular Shift
- XOR Without XORing
- Search Sorted Array
- Unbounded Search Sorted Array
- Rotation Count
- Search Circular Array
- First and Last Occurrence
- Count Occurrences
- Smallest Missing Number
- Smallest Missing Number II
- Floor and Ceil
- Search Nearly Sorted Array
- Count Ones
- Peak Element
- K Closest Elements
- Longest Common Prefix
- Implement Power Function
- Implement Square Root
- Check Min Heap
- Max Heap to Min Heap
- Kth Smallest Element
- Kth Largest Element
- Kth Largest Element II
- Merge Sorted Lists
- Connect N Ropes
- Replace Elements with Rank
- Longest Common Subsequence
- Longest Common Subsequence II
- Longest Common Subsequence III
- Longest Common Substring
- Longest Palindromic Subsequence
- Longest Repeated Subsequence
- Shortest Common Supersequence
- Shortest Common Supersequence II
- Longest Decreasing Subsequence
- Longest Bitonic Subsequence
- Max Sum Increasing Subsequence
- Edit Distance Problem
- Maximize Value
- 0/1 Knapsack Problem
- Partition Problem
- Subset Sum Problem
- Minimum Sum Partition Problem
- Longest Alternating Subsequence
- Linear Equation K Variables
- Word Break Problem
- Weighted Interval Scheduling
- Matrix Chain Multiplication
- Climbing Stairs
- Climbing Stairs II
- Pots of Gold Game
- Minimum Jumps
- Optimal Cost to Construct BST
- Maximum Sum Subsequence
- Nth Fibonacci Number
- Count Decodings
- Hat Check Problem
- Minimum Squares
- Truncate Array
- Dice Throw
- Minimum Weight Triangulation
- Longest Alternating Subarray
- Construct Linked List
- Construct Linked List II
- Pop Linked List Head
- Sorted Insert in Linked List
- Kth Node from End
- Delete Nodes Linked List
- Remove Redundant Nodes
- Add Number to Linked List
- Add Two Linked Lists
- Sort Linked List
- Dutch National Flag Problem II
- Sort Doubly Linked List
- Swap Nodes Linked List
- Swap Nodes Linked List II
- Detect Cycle Linked List
- Remove Cycle Linked List
- Split Linked List
- Split Linked List II
- Remove Duplicates Linked List
- Remove Duplicates Linked List II
- Clone Linked List
- Clone Linked List II
- Move Node Linked List
- Move Node Linked List II
- Sorted Intersect
- Shuffle Merge
- Shuffle Merge II
- Reverse Linked List
- Reverse Linked List II
- Reverse Linked List III
- Reverse Linked List IV
- Reverse Doubly Linked List
- Rearrange Linked List
- Rearrange Linked List II
- Rearrange Linked List III
- Rearrange Linked List IV
- Sorted Merge
- Sorted Merge II
- Sorted Merge III
- Sorted Merge IV
- Palindrome Linked List
- Palindrome Linked List II
- Update Random Pointer
- Lists Intersection Point
- Inorder Tree Traversal
- Preorder Tree Traversal
- Postorder Tree Traversal
- Level Order Traversal
- Spiral Order Traversal
- Reverse Level Order Traversal
- Check Identical Binary Trees
- Height of Binary Tree
- Height of Binary Tree II
- Height of Binary Tree III
- Clone Binary Tree
- Clone Binary Tree II
- Is Ancestor or Descendant
- Bottom View Binary Tree
- Top View Binary Tree
- Left View Binary Tree
- Right View Binary Tree
- Perfect Binary Tree Traversal
- Perfect Binary Tree Traversal II
- Boundary Traversal Binary Tree
- Diagonal Traversal Binary Tree
- Vertical Traversal Binary Tree
- Maximum Width Binary Tree
- Minimum Depth Binary Tree
- Corner Nodes in Each Level
- Cousin Nodes
- Cousin Nodes II
- Lowest Common Ancestor
- Ancestors of Binary Tree Node
- Height Balanced Binary Tree
- Height Balanced Binary Tree II
- Nodes Between Two Levels
- Distance Between Two Nodes
- K Distance Nodes from Leaves
- Transform Binary Tree
- Transform Binary Tree II
- Truncate Binary Tree
- Truncate Binary Tree II
- Sum Tree
- Root to Leaf Paths in Binary Tree
- Leaf to Root Paths in Binary Tree
- Mirror of Binary Tree
- Node Descendant Difference
- Alternate Levels Sum Difference
- Maximum Sum Path Binary Tree
- Maximum Sum Path Binary Tree II
- Maximum Sum Path Binary Tree III
- Construct Binary Tree
- Construct Binary Tree II
- Construct Binary Tree III
- Construct Binary Tree IV
- Construct Binary Tree V
- Construct Binary Tree VI
- Construct Cartesian Tree
- Construct LCRS Binary Tree
- Construct Expression Tree
- Evaluate Expression Tree
- Is Symmetric Binary Tree
- Is Complete Binary Tree
- Is Skewed Binary Tree
- Is Subtree
- Is Binary Tree Min Heap
- Diameter of Binary Tree
- Diagonal Sum Binary Tree
- Postorder from Inorder and Preorder
- Preorder from Inorder and Postorder
- Binary Trees with Same Inorder
- Maximum Independent Set Problem
- Next Node at Same Level
- Invert Alternate Levels
- Subtrees with Same Node Value
- Split Binary Tree
- Set Inorder Successor
- Vertical Sum Binary Tree
- Leaf Traversal Binary Tree
- Link Nodes Binary Tree
- Ternary Tree to Doubly Linked List
- Extract Binary Tree Leaves
- Binary Tree to Doubly Linked List
- Binary Tree to Doubly Linked List II
- Linked List to Complete Binary Tree
- Ancestor Matrix
- Construct BST
- Insert key into BST
- Search key in BST
- Delete key from BST
- Is Same BSTs
- Inorder Predecessor BST
- Inorder Successor BST
- Lowest Common Ancestor II
- Kth Smallest Node BST
- Kth Largest Node BST
- Floor and Ceil II
- 2 Sum BST
- 2 Sum BST II
- 3 Sum BST
- Transform BST
- Truncate BST
- Is Preorder Sequence of BST
- Is Skewed BST
- Nodes Within a Range in BST
- Subtrees Within a Range in BST
- Construct BST from Preorder
- Construct BST from Postorder
- Complete BST Traversal
- Merge BSTs to Doubly Linked List
- Merge Height Balanced BSTs
- Construct Height Balanced BST
- Construct Height Balanced BST II
- Construct Height Balanced BST III
- Convert Binary Tree to BST
- Largest BST Size
- Is BST
- Fix Binary Tree
- Probability
- Probability II
- Probability III
- Probability IV
- Probability V
- Probability VI
- Probability VII
- Probability VIII
- Is Bipartite Graph
- Is Connected Graph
- Is Acyclic Connected Graph
- Is DAG
- Topological Sort
- Root Vertex in Graph
- Connectivity Matrix
- Bridges in Graph
- K Colorable Graph
- Graph Coloring
- Is Strongly Connected Graph
- Detect Cycle in Graph
- Least Cost Path
- Least Cost Path II
- Least Cost Path III
- Greatest Cost Path
- Is Reachable Vertex
- Total Paths in Digraph
- Single Source Shortest Paths
- Single Source Shortest Paths II
- All Pairs Shortest Paths
- Minimum Spanning Tree
- Maximum Cost Path
- Negative Weight Cycle
- Hamiltonian Path
- Eulerian Path
- Eulerian Path II
- Eulerian Cycle
- Factorial
- Factorial Series
- Palindrome Number
- Primes in Range
- Minimum and Maximum Element
- Reverse Array
- Greatest Common Divisor
- Bezout Coefficients
- Cubes Sum
- Clock Angle Problem
- Tower of Hanoi Problem
- Sort Stack
- Reverse Stack
- Generate Binary Numbers
- Convert Number to Words
- Implement Strstr Function
- Shortest Superstring Problem