Introduction:
Welcome to my carefully curated list of Data Structures and Algorithms (DSA) problems. Here, you'll find detailed solutions for each problem, ranging from basic brute-force methods to highly optimized approaches. Whether you're gearing up for coding interviews or aiming to enhance your algorithmic problem-solving abilities, this page serves as your go-to resource.
How to Use This Page:
All problems are organized into specific categories such as Dynamic Programming, Graph Algorithms, and others, allowing you to easily navigate and find what you're looking for. For each problem, multiple solution levels are provided, including:
- Brute Force Solution: A basic approach that solves the problem but might not be the most efficient.
- Better Solution: An enhanced method that lowers time complexity, resulting in a faster solution.
- Optimal Solution: The most optimal approach in terms of time complexity.
- Space Optimization: An optimized version of the solution that also reduces space complexity.
Why Focus on Different Solutions?
In practical situations, the most efficient solution may not always be required or might be overly complex for the task at hand. By exploring and applying various approaches, you'll be better prepared to select the most suitable solution based on the specific constraints and needs of the problem.
Get Started
Browse the problems by category, experiment with the solutions, and enhance your problem-solving abilities. Don’t hesitate to share comments or suggestions if you have different methods or improvements to propose.
Problem Categories:
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Merge Sorted Array | 📄 | 📝 | Easy |
2 | Remove Element | 📄 | 📝 | Easy |
3 | Remove Duplicates from Sorted Array | 📄 | 📝 | Easy |
4 | Remove Duplicates from Sorted Array II | 📄 | 📝 | Medium |
5 | Majority Element | 📄 | 📝 | Easy |
6 | Rotate Array | 📄 | 📝 | Medium |
7 | Best Time to Buy and Sell Stock | 📄 | 📝 | Easy |
8 | Best Time to Buy and Sell Stock II | 📄 | 📝 | Medium |
9 | Jump Game | 📄 | 📝 | Medium |
10 | Jump Game II | 📄 | 📝 | Medium |
11 | H-Index | 📄 | 📝 | Medium |
12 | Insert Delete GetRandom O(1) | 📄 | 📝 | Medium |
13 | Product of Array Except Self | 📄 | 📝 | Medium |
14 | Gas Station | 📄 | 📝 | Medium |
15 | Candy | 📄 | 📝 | Hard |
16 | Trapping Rain Water | 📄 | 📝 | Hard |
17 | Roman to Integer | 📄 | 📝 | Easy |
18 | Integer to Roman | 📄 | 📝 | Medium |
19 | Length of Last Word | 📄 | 📝 | Easy |
20 | Longest Common Prefix | 📄 | 📝 | Easy |
21 | Reverse Words in a String | 📄 | 📝 | Medium |
22 | Zigzag Conversion | 📄 | 📝 | Medium |
23 | Find the Index of the First Occurrence in a String | 📄 | 📝 | Easy |
24 | Text Justification | 📄 | 📝 | Hard |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Valid Palindrome | 📄 | 📝 | Easy |
2 | Is Subsequence | 📄 | 📝 | Easy |
3 | Two Sum II - Input Array Is Sorted | 📄 | 📝 | Medium |
4 | Container With Most Water | 📄 | 📝 | Medium |
5 | 3Sum | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Minimum Size Subarray Sum | 📄 | 📝 | Medium |
2 | Longest Substring Without Repeating Characters | 📄 | 📝 | Medium |
3 | Substring with Concatenation of All Words | 📄 | 📝 | Hard |
4 | Minimum Window Substring | 📄 | 📝 | Hard |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Valid Sudoku | 📄 | 📝 | Medium |
2 | Spiral Matrix | 📄 | 📝 | Medium |
3 | Rotate Image | 📄 | 📝 | Medium |
4 | Set Matrix Zeroes | 📄 | 📝 | Medium |
5 | Game of Life | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Ransom Note | 📄 | 📝 | Easy |
2 | Isomorphic Strings | 📄 | 📝 | Easy |
3 | Word Pattern | 📄 | 📝 | Easy |
4 | Valid Anagram | 📄 | 📝 | Easy |
5 | Group Anagrams | 📄 | 📝 | Medium |
6 | Two Sum | 📄 | 📝 | Easy |
7 | Happy Number | 📄 | 📝 | Easy |
8 | Contains Duplicate II | 📄 | 📝 | Easy |
9 | Longest Consecutive Sequence | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Summary Ranges | 📄 | 📝 | Easy |
2 | Merge Intervals | 📄 | 📝 | Medium |
3 | Insert Interval | 📄 | 📝 | Medium |
4 | Minimum Number of Arrows to Burst Balloons | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Valid Parentheses | 📄 | 📝 | Easy |
2 | Simplify Path | 📄 | 📝 | Medium |
3 | Min Stack | 📄 | 📝 | Medium |
4 | Evaluate Reverse Polish Notation | 📄 | 📝 | Medium |
5 | Basic Calculator | 📄 | 📝 | Hard |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Linked List Cycle | 📄 | 📝 | Easy |
2 | Add Two Numbers | 📄 | 📝 | Medium |
3 | Merge Two Sorted Lists | 📄 | 📝 | Easy |
4 | Copy List with Random Pointer | 📄 | 📝 | Medium |
5 | Reverse Linked List II | 📄 | 📝 | Medium |
6 | Reverse Nodes in k-Group | 📄 | 📝 | Hard |
7 | Remove Nth Node From End of List | 📄 | 📝 | Medium |
8 | Remove Duplicates from Sorted List II | 📄 | 📝 | Medium |
9 | Rotate List | 📄 | 📝 | Medium |
10 | Partition List | 📄 | 📝 | Medium |
11 | LRU Cache | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Maximum Depth of Binary Tree | 📄 | 📝 | Easy |
2 | Same Tree | 📄 | 📝 | Easy |
3 | Invert Binary Tree | 📄 | 📝 | Easy |
4 | Symmetric Tree | 📄 | 📝 | Easy |
5 | Construct Binary Tree from Preorder and Inorder Traversal | 📄 | 📝 | Medium |
6 | Construct Binary Tree from Inorder and Postorder Traversal | 📄 | 📝 | Medium |
7 | Populating Next Right Pointers in Each Node II | 📄 | 📝 | Medium |
8 | Flatten Binary Tree to Linked List | 📄 | 📝 | Medium |
9 | Path Sum | 📄 | 📝 | Easy |
10 | Sum Root to Leaf Numbers | 📄 | 📝 | Medium |
11 | Binary Tree Maximum Path Sum | 📄 | 📝 | Hard |
12 | Binary Search Tree Iterator | 📄 | 📝 | Medium |
13 | Count Complete Tree Nodes | 📄 | 📝 | Easy |
14 | Lowest Common Ancestor of a Binary Tree | 📄 | 📝 | Medium |
15 | Binary Tree Right Side View | 📄 | 📝 | Medium |
16 | Average of Levels in Binary Tree | 📄 | 📝 | Easy |
17 | Binary Tree Level Order Traversal | 📄 | 📝 | Medium |
18 | Binary Tree Zigzag Level Order Traversal | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Binary Tree Right Side View | 📄 | 📝 | Medium |
2 | Average of Levels in Binary Tree | 📄 | 📝 | Easy |
3 | Binary Tree Level Order Traversal | 📄 | 📝 | Medium |
4 | Binary Tree Zigzag Level Order Traversal | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Minimum Absolute Difference in BST | 📄 | 📝 | Easy |
2 | Kth Smallest Element in a BST | 📄 | 📝 | Medium |
3 | Validate Binary Search Tree | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Number of Islands | 📄 | 📝 | Medium |
2 | Surrounded Regions | 📄 | 📝 | Medium |
3 | Clone Graph | 📄 | 📝 | Medium |
4 | Evaluate Division | 📄 | 📝 | Medium |
5 | Course Schedule | 📄 | 📝 | Medium |
6 | Course Schedule II | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Snakes and Ladders | 📄 | 📝 | Medium |
2 | Minimum Genetic Mutation | 📄 | 📝 | Medium |
3 | Word Ladder | 📄 | 📝 | Hard |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Implement Trie (Prefix Tree) | 📄 | 📝 | Medium |
2 | Design Add and Search Words Data Structure | 📄 | 📝 | Medium |
3 | Word Search II | 📄 | 📝 | Hard |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Letter Combinations of a Phone Number | 📄 | 📝 | Medium |
2 | Combinations | 📄 | 📝 | Medium |
3 | Permutations | 📄 | 📝 | Medium |
4 | Combination Sum | 📄 | 📝 | Medium |
5 | N-Queens II | 📄 | 📝 | Hard |
6 | Generate Parentheses | 📄 | 📝 | Medium |
7 | Word Search | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Convert Sorted Array to Binary Search Tree | 📄 | 📝 | Easy |
2 | Sort List | 📄 | 📝 | Medium |
3 | Construct Quad Tree | 📄 | 📝 | Medium |
4 | Merge k Sorted Lists | 📄 | 📝 | Hard |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Maximum Subarray | 📄 | 📝 | Medium |
2 | Maximum Sum Circular Subarray | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Search Insert Position | 📄 | 📝 | Easy |
2 | Search a 2D Matrix | 📄 | 📝 | Medium |
3 | Find Peak Element | 📄 | 📝 | Medium |
4 | Search in Rotated Sorted Array | 📄 | 📝 | Medium |
5 | Find First and Last Position of Element in Sorted Array | 📄 | 📝 | Medium |
6 | Find Minimum in Rotated Sorted Array | 📄 | 📝 | Medium |
7 | Median of Two Sorted Arrays | 📄 | 📝 | Hard |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Kth Largest Element in an Array | 📄 | 📝 | Medium |
2 | IPO | 📄 | 📝 | Hard |
3 | Find K Pairs with Smallest Sums | 📄 | 📝 | Medium |
4 | Find Median from Data Stream | 📄 | 📝 | Hard |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Add Binary | 📄 | 📝 | Easy |
2 | Reverse Bits | 📄 | 📝 | Easy |
3 | Number of 1 Bits | 📄 | 📝 | Easy |
4 | Single Number | 📄 | 📝 | Easy |
5 | Single Number II | 📄 | 📝 | Medium |
6 | Bitwise AND of Numbers Range | 📄 | 📝 | Medium |
Sr. No | Problem | Article | Practice | Difficulty |
---|---|---|---|---|
1 | Palindrome Number | 📄 | 📝 | Easy |
2 | Plus One | 📄 | 📝 | Easy |
3 | Factorial Trailing Zeroes | 📄 | 📝 | Medium |
4 | Sqrt(x) | 📄 | 📝 | Easy |
5 | Pow(x, n) | 📄 | 📝 | Medium |
6 | Max Points on a Line | 📄 | 📝 | Hard |
Summary
This approach offers a well-organized method for presenting your solutions, leading readers through the problem-solving process in a step-by-step manner. You can tailor the tone and specifics to match your personal style or target audience.