Welcome to my LeetCode DSA Solutions repository! This space is dedicated to solving and documenting solutions to LeetCode problems focused on Data Structures and Algorithms (DSA). Whether you're preparing for technical interviews πΌ, improving your problem-solving skills π§ , or just exploring the beauty of algorithms, this repo is here to help.
This repository contains Python π solutions to various LeetCode problems categorized by data structures and algorithms. Each solution is carefully written to be clean, efficient, and well-documented, making it easy for learners to understand and adapt.
- Solve a wide range of DSA problems to strengthen algorithmic thinking.
- Provide clear explanations and optimized code for each problem.
- Create a structured resource for interview preparation and learning.
Order | Description |
---|---|
π§± Arrays | The most fundamental data structure. Solving array problems helps build a strong foundation in algorithms. |
Builds on arrays and introduces efficient traversal techniques for solving problems like two-sum and subarray manipulation. | |
ποΈ Sliding Window | Extends two pointers to solve subarray/substring problems, often used in problems involving contiguous sequences. |
π’π Fast & Slow Pointers | Focuses on linked lists and cycle detection, building on pointer manipulation techniques. |
π Modified Binary Search | A foundational algorithm for searching in sorted data, often extended to solve more complex variations. |
π Merge Intervals | Introduces interval-based problems, which are common in real-world applications like scheduling and resource allocation. |
π K-way Merge | Extends merging concepts to handle multiple sorted inputs, such as merging k sorted lists or finding the smallest range. |
βοΈ 2 Heaps | Useful for solving problems involving medians or dynamic sets, leveraging min-heaps and max-heaps. |
π Top K Elements | Builds on heaps and sorting for finding top elements, such as the kth largest element or k closest points. |
βͺοΈπ Backtracking | Introduces recursion and combinatorial problem-solving, commonly used in problems involving subsets, permutations, and combinations. |
π‘ Dynamic Programming (DP) | A powerful technique for optimization and counting problems, using memoization or tabulation to solve subproblems efficiently. |
π³π Graph Traversal | Essential for solving problems involving networks, paths, or connectivity, using algorithms like DFS and BFS. |
π Topological Sorting | Builds on graph traversal for dependency resolution, commonly used in scheduling and ordering problems. |
π² Tree BFS/DFS | Fundamental for solving tree-based problems, including level-order traversal, path sums, and tree serialization. |
π In-place Traversal of Linked List | Advanced linked list manipulation without extra space, focusing on efficient pointer reassignment. |
Each problem will have its own folder with the following structure:
/problems
βββ {Problem_Name}/
β βββ solution.py # Python solution file
β βββ README.md # Problem description, approach, and complexity analysis
β βββ test_cases.py # Sample test cases (optional)
-
Clone the Repository:
git clone https://github.com/onyxwizard/leetcode.git cd leetcode
-
Explore Solutions:
Navigate through the /problems directory to find solutions by category or difficulty.
-
Run the Code:
Open the solution.py file in your favorite Python IDE or run it directly:
-
Contribute:
Contributions are welcome! If you'd like to add a new solution or improve an existing one, feel free to open a pull request.
Below is the list of problems under the Arrays pattern:
Problem | Difficulty | Acceptance Rate | Progress | Link | Solution |
---|---|---|---|---|---|
448. Find All Numbers Disappeared in an Array | Easy | 62.1% | π© | LeetCode | π |
136. Single Number | Easy | 75.5% | π© | LeetCode | π |
268. Missing Number | Easy | 69.6% | π© | LeetCode | π |
217. Contains Duplicate | Easy | 62.9% | π© | LeetCode | π |
128. Longest Consecutive Sequence | Medium | 47.1% | π© | LeetCode | π |
581. Shortest Unsorted Continuous Subarray | Medium | 37.3% | π© | LeetCode | π |
73. Set Matrix Zeroes | Medium | 59.2% | π© | LeetCode | π |
457. Circular Array Loop | Medium | 35.3% | β¬ | LeetCode | |
792. Number of Matching Subsequences | Medium | 50.7% | β¬ | LeetCode | |
238. Product of Array Except Self | Medium | 67.5% | β¬ | LeetCode | |
79. Word Search | Medium | 44.8% | β¬ | LeetCode | |
48. Rotate Image | Medium | 77.4% | β¬ | LeetCode | |
54. Spiral Matrix | Medium | 53.2% | β¬ | LeetCode | |
442. Find All Duplicates in an Array | Medium | 76.3% | β¬ | LeetCode | |
287. Find the Duplicate Number | Medium | 62.5% | π© | LeetCode | π |
41. First Missing Positive | Hard | 40.8% | β¬ | LeetCode |
Below is the list of problems under the Two Pointers pattern:
Problem | Difficulty | Acceptance Rate | Progress | Link | Solution |
---|---|---|---|---|---|
1. Two Sum | Easy | 55.3% | π© | LeetCode | π |
844. Backspace String Compare | Easy | 49.4% | π© | LeetCode | π |
83. Remove Duplicates from Sorted List | Easy | 54.5% | β¬ | LeetCode | |
977. Squares of a Sorted Array | Easy | 73.1% | π© | LeetCode | π |
259. 3Sum Smaller | Medium | 50.9% | β¬ | LeetCode | |
713. Subarray Product Less Than K | Medium | 52.5% | π© | LeetCode | π |
11. Container With Most Water | Medium | 57.4% | β¬ | LeetCode | |
75. Sort Colors | Medium | 66.6% | β¬ | LeetCode | |
15. 3Sum | Medium | 36.6% | β¬ | LeetCode | |
16. 3Sum Closest | Medium | 46.7% | β¬ | LeetCode | |
42. Trapping Rain Water | Hard | 64.5% | β¬ | LeetCode | |
76. Minimum Window Substring | Hard | 44.9% | β¬ | LeetCode |
Below is the list of problems under the Sliding Window pattern:
Problem | Difficulty | Acceptance Rate | Progress | Link | Solution |
---|---|---|---|---|---|
3. Longest Substring Without Repeating Characters | Medium | 36.5% | β¬ | LeetCode | |
424. Longest Repeating Character Replacement | Medium | 56.6% | β¬ | LeetCode | |
904. Fruit Into Baskets | Medium | 45.8% | β¬ | LeetCode | |
209. Minimum Size Subarray Sum | Medium | 48.9% | β¬ | LeetCode | |
340. Longest Substring with At Most K Distinct Characters | Medium | 49.4% | β¬ | LeetCode | |
567. Permutation in String | Medium | 46.9% | β¬ | LeetCode | |
76. Minimum Window Substring | Hard | 44.9% | β¬ | LeetCode | |
828. Count Unique Characters of All Substrings of a Given String | Hard | 52.7% | β¬ | LeetCode | |
239. Sliding Window Maximum | Hard | 47.3% | β¬ | LeetCode | |
995. Minimum Number of K Consecutive Bit Flips | Hard | 62.1% | β¬ | LeetCode | |
30. Substring with Concatenation of All Words | Hard | 32.8% | β¬ | LeetCode |
Below is the list of problems under the Fast & Slow Pointers pattern:
Problem Number | Title | Difficulty | Acceptance Rate | Status | Platform | Solution |
---|---|---|---|---|---|---|
234 | Palindrome Linked List | Easy | 55.4% | β¬ | LeetCode | |
203 | Remove Linked List Elements | Easy | 51.4% | β¬ | LeetCode | |
876 | Middle of the Linked List | Easy | 80.3% | β¬ | LeetCode | |
141 | Linked List Cycle | Easy | 52.1% | β¬ | LeetCode | |
83 | Remove Duplicates from Sorted List | Easy | 54.5% | β¬ | LeetCode | |
2 | Add Two Numbers | Medium | 45.7% | β¬ | LeetCode | |
142 | Linked List Cycle II | Medium | 54.3% | β¬ | LeetCode | |
143 | Reorder List | Medium | 61.9% | β¬ | LeetCode | |
19 | Remove Nth Node From End of List | Medium | 48.4% | β¬ | LeetCode | |
148 | Sort List | Medium | 61.1% | β¬ | LeetCode |
Below is the list of problems under the Modified Binary Search pattern:
Problem Number | Title | Difficulty | Acceptance Rate | Status | Platform | Solution |
---|---|---|---|---|---|---|
704 | Binary Search | Easy | 59.3% | β¬ | LeetCode | |
744 | Find Smallest Letter Greater Than Target | Easy | 53.7% | β¬ | LeetCode | |
33 | Search in Rotated Sorted Array | Medium | 42.5% | β¬ | LeetCode | |
162 | Find Peak Element | Medium | 46.4% | β¬ | LeetCode | |
74 | Search a 2D Matrix | Medium | 51.9% | β¬ | LeetCode | |
81 | Search in Rotated Sorted Array II | Medium | 38.7% | β¬ | LeetCode | |
852 | Peak Index in a Mountain Array | Medium | 67.7% | β¬ | LeetCode | |
153 | Find Minimum in Rotated Sorted Array | Medium | 52.3% | β¬ | LeetCode | |
327 | Count of Range Sum | Hard | 36.7% | β¬ | LeetCode |
Below is the list of problems under the Merge Intervals pattern:
Problem Number | Title | Difficulty | Acceptance Rate | Status | Platform | Solution |
---|---|---|---|---|---|---|
252 | Meeting Rooms | Easy | 58.8% | β¬ | LeetCode | |
435 | Non-overlapping Intervals | Medium | 55.1% | β¬ | LeetCode | |
452 | Minimum Number of Arrows to Burst Balloons | Medium | 60.1% | β¬ | LeetCode | |
56 | Merge Intervals | Medium | 49.0% | β¬ | LeetCode | |
57 | Insert Interval | Medium | 43.1% | β¬ | LeetCode | |
621 | Task Scheduler | Medium | 61.1% | β¬ | LeetCode | |
986 | Interval List Intersections | Medium | 72.5% | β¬ | LeetCode | |
253 | Meeting Rooms II | Medium | 52.0% | β¬ | LeetCode |
Below is the list of problems under the K-Way Merge pattern:
Problem Number | Title | Difficulty | Acceptance Rate | Status | Platform | Solution |
---|---|---|---|---|---|---|
21 | Merge Two Sorted Lists | Easy | 66.5% | β¬ | LeetCode | |
373 | Find K Pairs with Smallest Sums | Medium | 40.5% | β¬ | LeetCode | |
378 | Kth Smallest Element in a Sorted Matrix | Medium | 63.3% | β¬ | LeetCode | |
23 | Merge k Sorted Lists | Hard | 56.1% | β¬ | LeetCode | |
632 | Smallest Range Covering Elements from K Lists | Hard | 69.7% | β¬ | LeetCode |
Below is the list of problems under the 2 Heaps pattern:
Problem Number | Title | Difficulty | Acceptance Rate | Status | Platform | Solution |
---|---|---|---|---|---|---|
295 | Find Median from Data Stream | Hard | 53.1% | β¬ | LeetCode | |
480 | Sliding Window Median | Hard | 38.6% | β¬ | LeetCode | |
502 | IPO | Hard | 53.0% | β¬ | LeetCode |
Pattern | Progress |
---|---|
Arrays | π©β¬β¬β¬β¬ |
Two Pointers | β¬β¬β¬β¬β¬ |
Sliding Window | β¬β¬β¬β¬β¬ |
Fast & Slow Pointers | β¬β¬β¬β¬β¬ |
Modified Binary Search | β¬β¬β¬β¬β¬ |
Merge Intervals | β¬β¬β¬β¬β¬ |
K-way Merge | β¬β¬β¬β¬β¬ |
2 Heaps | β¬β¬β¬β¬β¬ |
Top K Elements | β¬β¬β¬β¬β¬ |
Backtracking | β¬β¬β¬β¬β¬ |
Dynamic Programming | β¬β¬β¬β¬β¬ |
Graph Traversal | β¬β¬β¬β¬β¬ |
Topological Sorting | β¬β¬β¬β¬β¬ |
Tree BFS | β¬β¬β¬β¬β¬ |
Tree DFS | β¬β¬β¬β¬β¬ |
In-place Traversal of LL | β¬β¬β¬β¬β¬ |
This repository is licensed under the MIT License. Feel free to use, modify, and distribute the code as per the license terms. Attribution is appreciated but not mandatory.
For more details, see the LICENSE file.
- Special thanks to LeetCode for providing an incredible platform to practice DSA problems.
- Some solutions may have been inspired or refined with the help of AI tools like ChatGPT or GitHub Copilot. e