A curated Data Structures & Algorithms (DSA) repository focused on problem-solving patterns (not random problem dumps).
Each pattern includes intuition, templates, pitfalls, and solutions with time/space complexity so you can learn once and reuse everywhere.
- Pattern-first learning: Binary Search, Two Pointers, Sliding Window, DFS/BFS, DP, Greedy, Backtracking, etc.
- Clean solutions: readable, consistent style, and interview-friendly.
- Explanations that teach: why the approach works, not just what to type.
- Complexity notes: time and space called out for each solution.
- Reusable templates: minimal “starter” code to apply patterns quickly.
- Start in the Patterns section below.
- Open the folder path for the pattern you want.
- Read that folder’s
README.mdfor:- when to use the pattern
- core idea / invariants
- template
- common mistakes
- curated problems + solutions in that folder
Tip: If you’re preparing for interviews, pick 1–2 patterns per week, then solve 10–20 problems per pattern.
Below are the main pattern “packages” (folder paths). Each folder should contain a README.md explanation page plus solutions.
patterns/binary-search/patterns/two-pointers/patterns/sliding-window/patterns/merge-intervals/
patterns/bfs/patterns/dfs/patterns/topological-sort/patterns/union-find/patterns/shortest-path/
patterns/dp-1d/patterns/dp-2d/patterns/dp-knapsack/patterns/dp-subsequence/
patterns/backtracking/patterns/recursion/
patterns/greedy/patterns/heap-priority-queue/
patterns/stack/patterns/queue/patterns/hashmap/patterns/trie/
patterns/math/patterns/bit-manipulation/
You can rename/reorder these based on your preferred curriculum.
This is a clean structure that scales as the repo grows:
patterns/binary-search/README.md(pattern explanation + templates + pitfalls + problem list)solutions/(or keep solutions in the folder root)
sliding-window/dp-1d/
templates/(optional: cross-pattern templates)notes/(optional: general notes, cheat sheets)README.md(this file)
To keep solutions consistent and easy to review, this repo follows these conventions:
-
File naming
- Use descriptive names:
lower_bound,first_true,rotated_sorted_array, etc. - If using numbered platforms, add a suffix:
two_sum_leetcode,aggressive_cows_gfg, etc.
- Use descriptive names:
-
Solution format (recommended)
- Problem summary (1–3 lines)
- Key idea / invariant
- Complexity
- Implementation
-
Complexity notation
- Time:
O(...) - Space:
O(...)(state if auxiliary space vs total space matters)
- Time:
A solution is considered “complete” when it has:
- A correct approach (handles edge cases)
- Clear variable names
- Complexity stated
- At least one of:
- brief proof/intuition, or
- invariants explained, or
- “why this pattern applies” note
This repo emphasizes templates you can memorize and adapt, such as:
- Binary Search on answer (first true / last true)
- Sliding Window (fixed vs variable window)
- BFS level-order
- DFS recursion with visited/parent
- DP state + transition + base cases
- Backtracking (choose → explore → unchoose)
Templates may live inside each pattern folder and/or in templates/.
A practical progression that builds confidence quickly:
- Arrays / Strings basics + Hashing
- Two Pointers + Sliding Window
- Binary Search (index) → Binary Search (answer space)
- Stack / Monotonic Stack
- Trees (DFS/BFS)
- Graphs (BFS/DFS → Topo Sort → Union-Find)
- Heaps + Greedy
- Dynamic Programming (1D → 2D → classic patterns)
- Backtracking (subsets/permutations/combinations)
If you want a simple accountability system, track it here:
- Binary Search — core templates completed
- Sliding Window — fixed + variable window completed
- Two Pointers — classic patterns completed
- BFS/DFS — templates + 10 problems each
- DP — 1D + 2D + knapsack basics
(If you don’t want checkboxes, remove this section.)
If you’re using this repo personally, treat this as your rulebook:
- Add problems only if they reinforce a pattern.
- Prefer fewer, higher-quality solutions over many rushed ones.
- If you revisit a problem and find a cleaner solution, replace it and add a short note on what improved.
If you plan to accept external contributions later, you can add:
- style rules
- required format
- PR checklist
- code review expectations
Add a license if you plan to share widely (MIT is a common choice).
If you’re unsure, you can leave this out until you decide.
This repo is built as a living notebook. If something is unclear:
- check the pattern
README.md - compare multiple solutions in the same pattern
- add a short note to improve future-you’s understanding