This repository collects my LeetCode solutions. Each problem is solved with clarity and efficiency in mind, and the repo is organized so you can browse solutions by problem number. The list below contains problems I have solved and uploaded here.
- Two Sum
- Add Two Numbers
- Reverse Integer
- Palindrome Number
- Container With Most Water
- Longest Common Prefix
- Valid Parentheses
- Merge k Sorted Lists
- Remove Duplicates from Sorted Array
- Remove Element
- Search in Rotated Sorted Array
- Find First and Last Position of Element in Sorted Array
- Search Insert Position
- Rotate Image
- Pow(x, n)
- Maximum Subarray
- Spiral Matrix
- Plus One
- Add Binary
- Sqrt(x)
- Sort Colors
- Subsets
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted List
- Merge Sorted Array
- Best Time to Buy and Sell Stock
- Linked List Cycle
- Linked List Cycle II
- Reorder List
- Binary Tree Preorder Traversal
- Binary Tree Postorder Traversal
- Maximum Product Subarray
- Find Minimum in Rotated Sorted Array
- Find Peak Element
- Two Sum II - Input Array Is Sorted
- Majority Element
- Rotate Array
- Reverse Bits
- Number of 1 Bits
- Count Primes
- Minimum Size Subarray Sum
- Contains Duplicate
- Power of Two
- Palindrome Linked List
- Delete Node in a Linked List
- Product of Array Except Self
- Valid Anagram
- Add Digits
- Missing Number
- Move Zeroes
- Find the Duplicate Number
- Longest Increasing Subsequence
- Power of Three
- Reverse String
- Intersection of Two Arrays
- Valid Perfect Square
- Guess Number Higher or Lower
- First Unique Character in a String
- Fizz Buzz
- Third Maximum Number
- Find All Duplicates in an Array
- Perfect Number
- Fibonacci Number
- Subarray Sum Equals K
- Maximum Product of Three Numbers
- Maximum Average Subarray I
- Binary Search
- Subarray Product Less Than K
- Peak Index in a Mountain Array
- Transpose Matrix
- Minimum Absolute Difference
- Count Negative Numbers in a Sorted Matrix
- Maximum Points You Can Obtain from Cards
- Number of Smooth Descent Periods of a Stock
- Maximum Count of Positive Integer and Negative Integer
- Minimum Operations to Exceed Threshold Value I
- Delete Nodes From Linked List Present in Array
- Minimum Operations to Make Array Sum Divisible by K
- GCD of Odd and Even Sums
- Running Sum of 1d Array
This repo is a personal collection of problem solutions from LeetCode. Problems are individually implemented and aim to illustrate clear approaches, typical patterns, and optimized implementations where appropriate. Use the problem list above to find a specific problem and open its corresponding file to inspect the solution.
Below are the major algorithmic topics and key points covered across the problems in this repository. For each topic, I include concise explanations and representative problems from this repo.
-
Arrays & Hashing:
- Key ideas: indexing, in-place updates, frequency maps, element-to-index mappings.
- Use cases: counting, deduplication, lookup in O(1).
- Representative problems:
Two Sum(1),Contains Duplicate(217),Intersection of Two Arrays(349),Move Zeroes(283),Missing Number(268),Find All Duplicates in an Array(442).
-
Two Pointers:
- Key ideas: left/right pointers, in-place swaps, shrinking/expanding windows for sorted arrays or paired operations.
- Representative problems:
Container With Most Water(11),Two Sum II(167),Remove Duplicates from Sorted Array(26),Remove Element(27),Sort Colors(75).
-
Sliding Window:
- Key ideas: variable-size window, maintain running aggregates, optimize subarray problems to O(n).
- Representative problems:
Minimum Size Subarray Sum(209),Subarray Product Less Than K(713),Maximum Average Subarray I(643).
-
Prefix Sum & Hashing:
- Key ideas: prefix sums to transform range-sum queries into constant-time checks; use hashmaps to store seen sums/indices.
- Representative problems:
Subarray Sum Equals K(560),Product of Array Except Self(238) (prefix-like transforms),Missing Number(268).
-
Sorting & Partitioning:
- Key ideas: sort + two-pointer, partition (Dutch National Flag), selection for k-th largest, use sorting to simplify logic.
- Representative problems:
Sort Colors(75),Maximum Product of Three Numbers(628),Merge Sorted Array(88).
-
Binary Search & Variants:
- Key ideas: search on index/answer, handle edge cases (duplicates, rotated arrays), use while-loops with mid computation.
- Representative problems:
Sqrt(x)(69),Find Minimum in Rotated Sorted Array(153),Search in Rotated Sorted Array(33),Binary Search(704).
-
Dynamic Programming (DP):
- Key ideas: define state, recurrence, optimize space when possible, handle base cases.
- Representative problems:
Maximum Subarray(53) (Kadane — 1D DP),Maximum Product Subarray(152),Longest Increasing Subsequence(300),Fibonacci Number(509).
-
Greedy:
- Key ideas: local optimal choices lead to global optimum, sorting + greedy selection.
- Representative problems:
Best Time to Buy and Sell Stock(121) (single pass greedy),Maximum Product of Three Numbers(628).
-
Bit Manipulation & Math:
- Key ideas: bit ops for flags/counting bits, arithmetic tricks, modular considerations.
- Representative problems:
Reverse Bits(190),Number of 1 Bits(191),Power of Two(231),Add Digits(258),Pow(x, n)(50).
-
Linked List Techniques:
- Key ideas: slow/fast pointers, cycle detection, two-pointer removal, list merging.
- Representative problems:
Linked List Cycle(141),Linked List Cycle II(142),Palindrome Linked List(234),Merge k Sorted Lists(23).
-
Recursion, Tree Traversal & DFS:
- Key ideas: recursion for traversal, stack-based iterative alternatives, preorder/inorder/postorder patterns.
- Representative problems:
Binary Tree Preorder Traversal(144).
-
Number Theory & Primes:
- Key ideas: sieve, primality checks, factorization where relevant.
- Representative problems:
Count Primes(204),Perfect Number(507),Valid Perfect Square(367).
-
Windowed and Monotonic Methods:
- Key ideas: monotonic queues/stacks for range maxima/minima and optimized sliding-window variants.
- Representative problems:
Peak Index in a Mountain Array(852),Number of Smooth Descent Periods of a Stock(2110) (pattern counting).
Each solution typically includes a short explanation in the file header and attempts to show the pattern used so the approach is reusable across similar problems.
- Root: problem files (named by problem or number). See the problem list above.
README.md: this documentation.
- Clone the repo:
git clone https://github.com/Aniketgudgal/DSA_Leet_Questions.git
cd DSA_Leet_Questions- Open the solution file for a problem (files are organized per problem). Each file contains a solution and usually a small test or example usage in comments.
- Run the file using the language runtime your solution is implemented in (Python, Java, C++, etc.). Example for Python:
python path/to/problem_solution.pyIf you want, I can standardize runners or add a small test harness — tell me which language you'd like prioritized.
- Add solutions in a clear file-naming format (e.g.,
001_two_sum.pyor1_two_sum.cpp). - Include a brief explanation at the top of each solution file describing the approach and complexity.
- Add tests or example usage for your solution where possible.
For questions or suggestions, contact: [email protected]
Thank you for exploring these solutions — keep practicing and refining patterns!