A structured collection of my LeetCode solutions, DSA practice, problem-solving approaches, and algorithmic learning journey.
Welcome to my LeetCode Solutions repository! 🚀
This repository contains my solutions to problems I solve while practicing Data Structures and Algorithms (DSA) on LeetCode.
The main goal of this repository is not just to collect accepted solutions, but to build a strong understanding of:
- 🧠 Problem-solving techniques
- 📚 Data Structures
- ⚡ Algorithms
- ⏱️ Time and Space Complexity
- 🔍 Pattern recognition
- 🧩 Logical thinking
- 💻 Competitive programming
- 🎯 Technical interview preparation
Every problem is approached with the intention of understanding why the solution works, rather than simply obtaining an accepted submission.
This repository will continuously grow as I solve more problems and improve my problem-solving skills.
The primary objectives of this repository are:
- Build strong fundamentals in Data Structures and Algorithms.
- Develop efficient problem-solving techniques.
- Practice writing clean and readable code.
- Understand different algorithmic patterns.
- Improve time and space complexity analysis.
- Prepare for coding interviews and technical assessments.
- Maintain a consistent daily coding practice.
- Track my progress throughout my DSA journey.
- Learn multiple approaches to the same problem.
- Build a publicly accessible reference for future revision.
The repository is organized around the major DSA concepts commonly used in coding interviews and competitive programming.
- Arrays
- Strings
- Hash Tables
- Sorting
- Searching
- Two Pointers
- Sliding Window
- Prefix Sum
- Basic Recursion
- Mathematical Problems
- Bit Manipulation
- Linked Lists
- Stacks
- Queues
- Binary Trees
- Binary Search Trees
- Heaps
- Priority Queues
- Backtracking
- Greedy Algorithms
- Intervals
- Matrix Problems
- Graphs
- Dynamic Programming
- Advanced Backtracking
- Advanced Graph Algorithms
- Trie
- Union Find / Disjoint Set Union
- Topological Sorting
- Shortest Path Algorithms
- Minimum Spanning Tree
- Advanced Binary Search
- Advanced Data Structures
The repository follows a topic-based structure to make solutions easy to find and revise.
Leetcode-Solutions/
│
├── README.md
│
├── Arrays/
│ ├── Two_Sum.py
│ ├── Best_Time_to_Buy_and_Sell_Stock.py
│ └── ...
│
├── Strings/
│ ├── Valid_Anagram.py
│ ├── Longest_Common_Prefix.py
│ └── ...
│
├── Hashing/
│ ├── Contains_Duplicate.py
│ └── ...
│
├── Two_Pointers/
│ ├── Valid_Palindrome.py
│ └── ...
│
├── Sliding_Window/
│ ├── Longest_Substring_Without_Repeating_Characters.py
│ └── ...
│
├── Linked_List/
│ ├── Reverse_Linked_List.py
│ ├── Merge_Two_Sorted_Lists.py
│ └── ...
│
├── Stack/
│ ├── Valid_Parentheses.py
│ └── ...
│
├── Queue/
│ └── ...
│
├── Binary_Tree/
│ ├── Maximum_Depth_of_Binary_Tree.py
│ └── ...
│
├── Binary_Search/
│ ├── Binary_Search.py
│ └── ...
│
├── Heap/
│ └── ...
│
├── Greedy/
│ └── ...
│
├── Backtracking/
│ └── ...
│
├── Graph/
│ └── ...
│
├── Dynamic_Programming/
│ └── ...
│
└── Bit_Manipulation/
└── ...
The folder structure may evolve as the repository grows.
Each solution aims to follow a consistent structure.
For example:
# Problem: Two Sum
# Difficulty: Easy
# Topic: Array, Hash Table
# LeetCode: 1
class Solution:
def twoSum(self, nums, target):
seen = {}
for i, num in enumerate(nums):
complement = target - num
if complement in seen:
return [seen[complement], i]
seen[num] = iWhenever appropriate, solutions include:
- Problem name
- LeetCode problem number
- Difficulty
- Topic
- Approach
- Code
- Time complexity
- Space complexity
- Important observations
Understanding complexity is an important part of this repository.
For every important solution, I try to analyze:
How the execution time grows as the input size increases.
Examples:
O(1) Constant
O(log n) Logarithmic
O(n) Linear
O(n log n) Linearithmic
O(n²) Quadratic
O(2ⁿ) Exponential
O(n!) Factorial
How much additional memory the algorithm requires.
Examples:
O(1) Constant extra space
O(n) Linear extra space
O(log n) Recursive/stack space
O(n²) Quadratic space
The goal is to gradually learn how to replace inefficient approaches with optimized ones.
One of the major goals of this repository is to recognize reusable problem-solving patterns.
Useful for:
- Sorted arrays
- Pair problems
- Palindrome problems
- Removing duplicates
- In-place array manipulation
General idea:
left →
← right
Useful for:
- Subarrays
- Substrings
- Maximum/minimum windows
- Longest/shortest valid sequences
Typical structure:
left = 0
for right in range(n):
# expand window
while condition_is_invalid:
# shrink window
left += 1
Useful for:
- Frequency counting
- Duplicate detection
- Pair-sum problems
- Fast lookups
- Grouping elements
Typical Python tools:
dict
set
collections.Counter
defaultdictUseful when the search space is sorted or when a monotonic condition exists.
Typical complexity:
O(log n)
Commonly used with linked lists.
Applications include:
- Detecting cycles
- Finding the middle node
- Finding cycle entry points
Useful for:
- Trees
- Graph traversal
- Backtracking
- Divide-and-conquer
Useful for:
- Permutations
- Combinations
- Subsets
- N-Queens
- Sudoku
- Constraint-based problems
General pattern:
Choose
↓
Explore
↓
Undo
Greedy algorithms make the best available local decision with the expectation that it leads to an optimal solution.
Common applications:
- Activity selection
- Jump problems
- Interval scheduling
- Minimum number of operations
DP is used when a problem contains:
- Overlapping subproblems
- Optimal substructure
Typical approaches:
Top-Down
Memoization
Bottom-Up
Tabulation
Important algorithms include:
BFS
DFS
Dijkstra
Topological Sort
Union Find
Minimum Spanning Tree
Problems are categorized according to their LeetCode difficulty.
| Difficulty | Description |
|---|---|
| 🟢 Easy | Fundamental concepts and basic patterns |
| 🟡 Medium | Requires stronger logic and optimization |
| 🔴 Hard | Advanced algorithms and complex reasoning |
The objective is to gradually progress from:
Easy
↓
Medium
↓
Hard
rather than trying to solve only difficult problems from the beginning.
A well-documented solution may follow this format:
Problem:
Two Sum
Problem Number:
1
Difficulty:
Easy
Topics:
Array, Hash Table
Approach:
Use a hash map to store previously visited numbers.
For every number, calculate its complement with respect
to the target. If the complement already exists, return
the corresponding indices.
Time Complexity:
O(n)
Space Complexity:
O(n)
This makes the repository useful not only for submissions but also for revision before interviews and exams.
My approach to solving problems follows a structured process.
Before writing code:
- Read the problem carefully.
- Identify the input.
- Identify the expected output.
- Understand the constraints.
- Check edge cases.
First determine the simplest possible solution.
This helps understand:
- What the problem is asking.
- Why the brute-force solution works.
- Where the inefficiency comes from.
Ask:
Can hashing help?
Can two pointers help?
Can I use a sliding window?
Is binary search possible?
Can this be solved recursively?
Is this a DP problem?
Is this a graph problem?
Compare possible approaches based on:
- Time complexity
- Space complexity
- Code simplicity
- Input constraints
Write clean and readable code.
Check:
- Normal cases
- Edge cases
- Empty input
- Duplicate values
- Large input
- Negative values
- Boundary conditions
Finally document:
Time Complexity
Space Complexity
Approach
Key Insight
The repository is intended to act as a long-term DSA progress tracker.
A typical progress table can be maintained as follows:
| Category | Problems Solved |
|---|---|
| Arrays | 🔄 Updating |
| Strings | 🔄 Updating |
| Hashing | 🔄 Updating |
| Two Pointers | 🔄 Updating |
| Sliding Window | 🔄 Updating |
| Linked Lists | 🔄 Updating |
| Stack | 🔄 Updating |
| Queue | 🔄 Updating |
| Binary Search | 🔄 Updating |
| Trees | 🔄 Updating |
| Heap | 🔄 Updating |
| Graphs | 🔄 Updating |
| Greedy | 🔄 Updating |
| Backtracking | 🔄 Updating |
| Dynamic Programming | 🔄 Updating |
The numbers will be updated as more problems are solved.
- Arrays
- Strings
- Hashing
- Sorting
- Searching
- Two Pointers
- Sliding Window
- Prefix Sum
- Linked Lists
- Stacks
- Queues
- Deques
- Binary Trees
- Binary Search Trees
- Heaps
- Tries
- Recursion
- Backtracking
- Greedy
- Graphs
- Dynamic Programming
- Union Find
- Advanced Graph Algorithms
- Solve problems without hints
- Improve speed
- Practice timed contests
- Revise common patterns
- Solve company-tagged problems
- Practice mock interviews
- Revisit previously solved problems
This repository follows a few important principles:
The objective is to understand the algorithm instead of memorizing code.
An accepted solution is not always the best solution.
Wrong answers and failed approaches are part of the learning process.
Many seemingly different problems can be solved using the same underlying pattern.
Readable code is easier to debug, maintain, and explain during interviews.
Regular practice is more valuable than solving many problems once and stopping.
The primary language used in this repository is:
Python is used because of its:
- Simple syntax
- Powerful built-in data structures
- Large standard library
- Fast implementation
- Excellent support for algorithmic problem solving
Commonly used Python features include:
list
dict
set
tuple
deque
heapq
Counter
defaultdict
enumerate()
zip()
sorted()Clone the repository:
git clone https://github.com/<your-username>/Leetcode-Solutions.gitMove into the repository:
cd Leetcode-SolutionsRun a Python solution:
python filename.pyFor example:
python Arrays/Two_Sum.pySome files are written specifically for the LeetCode platform and may contain only the
Solutionclass rather than a standalone input/output program.
This repository can be useful for:
Study the approach behind each problem.
Return to previously solved problems and review important patterns.
Practice frequently asked DSA concepts.
Identify which algorithmic technique applies to a new problem.
Use the repository to measure improvement over time.
As the repository grows, I plan to add:
- 📌 More LeetCode problems
- 🧠 Detailed explanations
- ⚡ Optimized approaches
- 📊 Complexity analysis
- 🗂️ Better topic categorization
- 🔥 Important DSA patterns
- 🎯 Interview-focused problem sets
- 🏢 Company-wise problems
- 📅 Daily/weekly progress tracking
- 📝 Revision notes
- 🧪 Test cases
- 🔄 Multiple approaches for important problems
This repository is primarily created for personal learning and DSA practice, but suggestions and improvements are welcome.
If you find:
- A bug
- An incorrect solution
- A better approach
- A missing edge case
- An optimization
- A documentation improvement
feel free to open an Issue or submit a Pull Request.
If you find this repository useful for your own DSA preparation, consider giving it a ⭐.
It helps support the project and encourages me to keep improving and adding more solutions.
Instead of solving problems randomly, focus on patterns.
A useful progression is:
Arrays
↓
Hashing
↓
Two Pointers
↓
Sliding Window
↓
Stack & Queue
↓
Binary Search
↓
Linked Lists
↓
Trees
↓
Heap
↓
Graphs
↓
Greedy
↓
Backtracking
↓
Dynamic Programming
Once the fundamentals become comfortable, start mixing different patterns so that you learn to identify the correct technique without being explicitly told which one to use.
When facing a new problem, ask yourself:
1. What exactly is being asked?
2. What are the constraints?
3. What would the brute-force solution look like?
4. Can I reduce repeated work?
5. Can hashing help?
6. Can I sort the input?
7. Can I use two pointers?
8. Can I use a sliding window?
9. Is binary search applicable?
10. Is recursion useful?
11. Is there an overlapping-subproblem structure?
12. Can I improve the time complexity?
13. What edge cases can break my solution?
These questions help transform problem solving from guessing into a systematic process.
The ultimate goal of this repository is not simply to achieve a large number of solved problems.
The real goal is to become better at:
Thinking → Analyzing → Designing → Optimizing → Implementing → Explaining
Every solved problem is another step toward becoming a stronger software developer and problem solver.
Solve problems. Learn patterns. Optimize solutions. Build consistency.
💻 Keep Coding • 🧠 Keep Learning • 🚀 Keep Improving
Made with ❤️ for the DSA journey.