Important
Stop grinding random LeetCode questions. Blindly memorizing hundreds of solutions leads to interview anxiety and failure whenever a slight variation appears.
Instead, master patterns. When you understand why a technique works, what triggers it, and how to optimize repeated work, you can recognize and solve unseen interview problems effortlessly.
| π― Patterns Covered | π’ Easy Problems | π‘ Medium Problems | π΄ Hard Problems | π Total Implemented |
|---|---|---|---|---|
| 11 Core Modules | 121 Foundations | 227 Interview Core | 79 Bar-Raisers | 427+ Full Solutions |
Follow this progressive order to build rock-solid algorithmic intuition from linear structures to advanced optimization.
flowchart TD
classDef foundation fill:#0a192f,stroke:#00f5ff,stroke-width:2px,color:#00f5ff;
classDef linear fill:#0d2040,stroke:#2563eb,stroke-width:2px,color:#7ef9ff;
classDef search fill:#1f1338,stroke:#a855f7,stroke-width:2px,color:#e9d5ff;
classDef advanced fill:#1e293b,stroke:#00FF00,stroke-width:2px,color:#4ade80;
subgraph Phase1 ["β‘ Phase 1: Foundations"]
A["π¦ 01. Arrays & Two Pointers"]:::foundation --> B["πͺ 02. Sliding Window & Prefix Sum"]:::foundation
end
subgraph Phase2 ["π Phase 2: Linear Data Structures"]
B --> C["π€ 03. Strings & Hashing"]:::linear
C --> D["π 04. Linked Lists"]:::linear
D --> E["π 05. Stacks & Queues"]:::linear
end
subgraph Phase3 ["π― Phase 3: Search & Hierarchies"]
E --> F["π― 06. Binary Search"]:::search
F --> G["π³ 07. Trees & BST"]:::search
end
subgraph Phase4 ["π§ Phase 4: Non-Linear & Optimization"]
G --> H["β°οΈ 08. Heaps & Greedy"]:::advanced
H --> I["π§© 09. Backtracking"]:::advanced
I --> J["πΈοΈ 10. Graphs"]:::advanced
J --> K["π§ 11. Dynamic Programming"]:::advanced
end
Every topic contains carefully curated problems classified into Easy, Medium, and Hard. Click [Explore Module β] to access topic-specific roadmaps and direct problem links.
| No. | Module / Topic | Core Concepts & Sub-Patterns | π’ Easy | π‘ Med | π΄ Hard | π Total | Action |
|---|---|---|---|---|---|---|---|
| 01 | π¦ Arrays | Prefix Sum, Kadane, Two Pointers, In-Place Manipulation, Dutch Flag | 19 | 35 | 3 | 57 | Explore Module β |
| 02 | πͺ Sliding Window & Prefix | Fixed/Dynamic Window, Range Frequency, Subarray Sums, Suffix Max | 16 | 25 | 8 | 49 | Explore Module β |
| 03 | π€ Strings & Hashing | Anagrams, Rolling Hash, Frequency Counting, Palindromes, State Tracking | 20 | 26 | 14 | 60 | Explore Module β |
| 04 | π Linked List | Fast & Slow Pointers, In-Place Reversal, Cycle Detection, Sentinel Nodes | 16 | 25 | 9 | 50 | Explore Module β |
| 05 | π Stack & Queue | Monotonic Stack, Next Greater Element, Queue BFS, Parentheses Validation | 16 | 22 | 11 | 49 | Explore Module β |
| 06 | π― Binary Search | Search in Rotated Arrays, Binary Search on Answer Space, Peak Elements | 10 | 24 | 16 | 50 | Explore Module β |
| 07 | π³ Trees & BST | Tree Traversals (DFS/BFS), Diameter, LCA, BST Properties, Path Sums | 18 | 17 | 7 | 42 | Explore Module β |
| 08 | β°οΈ Heap & Greedy | Min/Max Heaps, Top-K Frequent, Interval Scheduling, Greedy Choice Property | 4 | 12 | 4 | 20 | Explore Module β |
| 09 | π§© Backtracking | Permutations, Combinations, Subsets, Constraint Propagation, Pruning | 0 | 16 | 4 | 20 | Explore Module β |
| 10 | πΈοΈ Graphs | BFS/DFS, Cycle Detection, Topological Sort, Shortest Path, Disjoint Set Union | 1 | 17 | 2 | 20 | Explore Module β |
| 11 | π§ Dynamic Programming | 1D Memoization/Tabulation, 2D Grid DP, Knapsack Variations, Subsequences | 1 | 8 | 1 | 10 | Explore Module β |
| TOTAL | All 11 Modules Combined | Comprehensive Full-Stack Interview Mastery | 121 | 227 | 79 | 427 | Begin Practice π |
Follow this battle-tested mental sequence for every problem before touching the keyboard:
ββββββββββββββββββββββββββββββββ
β 1. Restate Input & Output β
ββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββΌββββββββββββββββ
β 2. Audit Constraints & Big-O β
ββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββΌββββββββββββββββ
β 3. Identify Pattern Triggers β
ββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββΌββββββββββββββββ
β 4. Mental Brute Force Model β
ββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββΌββββββββββββββββ
β 5. Optimize Redundant Work β
ββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββΌββββββββββββββββ
β 6. Dry Run on Edge Cases β
ββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββΌββββββββββββββββ
β 7. Write Clean, Modular Code β
ββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββΌββββββββββββββββ
β 8. Analyze Time & Space β
ββββββββββββββββββββββββββββββββ
- Restate Input & Output: Clearly specify types, expected null/empty behaviors, and return values.
-
Audit Constraints: Determine your allowed complexity budget.
-
$N \le 10^5 \to O(N)$ or$O(N \log N)$ $N \le 10^3 \to O(N^2)$ -
$N \le 20 \to O(2^N)$ or$O(N!)$ (Backtracking)
-
- Identify Pattern Triggers: Is it sorted? Are continuous elements queried? Are choices repetitive?
- Mental Brute Force: What is the most obvious solution? Why is it slow?
- Optimize Redundant Work: Replace nested loops with HashMaps, Two Pointers, Monotonic Stacks, or DP state tables.
- Dry-Run Edge Cases: Check empty arrays, single elements, identical values, negative numbers, and boundary indices.
- Clean Implementation: Use intuitive naming, handle base cases upfront, and avoid convoluted nested branches.
-
Complexity Audit: Explicitly state both Time and Space complexities (
$O(N)$ ,$O(1)$ , etc.).
Keep this cheat sheet handy during interview preparation to instantly connect question cues to optimal techniques:
| Problem Signal & Cue | First Pattern to Try | Time Budget | Signature Problem |
|---|---|---|---|
| Sorted array, search target or pair | Two Pointers / Binary Search |
|
Two Sum II, 3Sum |
| Continuous subarray / substring condition | Sliding Window | Longest Substring Without Repeating Characters | |
| Repeated range sum or query count | Prefix Sum / Difference Array |
|
Subarray Sum Equals K |
| Instant lookups, anagrams, frequency | HashMap / HashSet / Frequency Array | Group Anagrams | |
| Next greater / smaller element, histograms | Monotonic Stack | Daily Temperatures, Trapping Rain Water | |
| Top K elements, dynamic median | Min/Max Heap (PriorityQueue) | Kth Largest Element | |
| Monotonic predicate ("Is value |
Binary Search on Answer Space | Koko Eating Bananas | |
| Generate all permutations / combinations | Backtracking with Pruning | Exponential | N-Queens, Subsets |
| Shortest unweighted path, level order | BFS (Queue) | Binary Tree Level Order, Word Ladder | |
| Connected components, cycle, tree paths | DFS / Disjoint Set Union (DSU) | Number of Islands | |
| Task scheduling with prerequisites | Topological Sort (Kahn's / DFS) | Course Schedule | |
| Overlapping subproblems + optimal substructure | Dynamic Programming | Polynomial | Coin Change, Longest Common Subsequence |
| Interval overlaps, merging, scheduling | Sort by Start/End + Greedy | Merge Intervals | |
| Cycle detection or midpoint in Linked List | Floyd's Tortoise & Hare (Fast/Slow) |
|
Linked List Cycle |
π¦ 1. Arrays & Two Pointers (Click to expand)
-
Core Intuition: Understand index transitions. If unsorted, consider hash tables, prefix sums, or sorting. If sorted, two pointers (
leftandright) allow skipping unnecessary comparisons. -
Key Sub-Patterns:
- Opposite-Direction Pointers: Palindrome checks, 2Sum sorted, container with most water.
- Same-Direction Pointers (Read/Write): Removing duplicates, moving zeroes in-place.
-
Dutch National Flag (3 Pointers): Partitioning values (
$<$ ,$=$ ,$>$ pivot) in a single pass.
- Common Pitfalls: Off-by-one errors on boundary conditions, integer overflow on array sums.
πͺ 2. Sliding Window & Prefix Sum (Click to expand)
- Core Intuition: Solves subarray and substring challenges without recomputing contiguous elements from scratch.
-
Key Sub-Patterns:
-
Fixed Window: Window size
$K$ remains constant; slide right by addingarr[r]and subtractingarr[l]. -
Variable Window: Expand
rto satisfy condition; shrinklwhen invalid to restore constraint. - Prefix Sum + HashMap: When subarrays can have negative numbers, sliding window fails; store cumulative sum frequencies.
-
Fixed Window: Window size
- Common Pitfalls: Forgetting to update the optimal answer before/after shrinking, mixing up 0-indexed prefix arrays.
π€ 3. Strings & Hashing (Click to expand)
-
Core Intuition: Strings are character arrays. Count frequencies with constant space (
$O(1)$ auxiliary memory usingint[26]orint[128]). -
Key Sub-Patterns:
- Anagram Detection: Sorted key strings or frequency vectors.
-
Rolling Hash (Rabin-Karp): Substring matching in
$O(N)$ average time. - State Encoding: Transforming board/string states into hashable string representations.
-
Common Pitfalls: Creating too many intermediate
Stringobjects (useStringBuilderin Java to prevent memory spikes).
π 4. Linked Lists (Click to expand)
- Core Intuition: Pointer manipulation without random array access. Sentinel (dummy) head nodes eliminate edge cases for head deletions and insertions.
-
Key Sub-Patterns:
-
Fast & Slow Pointers: Midpoint detection, cycle discovery (Floyd's algorithm), finding the
$k$ -th node from the end. -
In-Place Pointer Reversal: Maintain
prev,curr,nextpointers to reverse in$O(1)$ memory. - Merge & Partition: Dividing lists for Merge Sort or reordering around pivot values.
-
Fast & Slow Pointers: Midpoint detection, cycle discovery (Floyd's algorithm), finding the
-
Common Pitfalls: Losing pointer references before reassignment; failing to set the last node's
nexttonull.
π 5. Stack & Queue (Click to expand)
- Core Intuition: Stack = LIFO (Last-In First-Out) for backtracking/nesting; Queue = FIFO (First-In First-Out) for level-order flow.
-
Key Sub-Patterns:
-
Monotonic Stack: Maintain strictly increasing or decreasing elements; immediately provides the "Next Greater" or "Previous Smaller" element in
$O(N)$ total time. - Parentheses & Nested Structures: Push open brackets, match with tops on close brackets.
-
Monotonic Deque: Sliding window maximum/minimum in
$O(1)$ amortized per slide.
-
Monotonic Stack: Maintain strictly increasing or decreasing elements; immediately provides the "Next Greater" or "Previous Smaller" element in
-
Common Pitfalls: Popping from an empty stack/queue without checking
.isEmpty().
π― 6. Binary Search (Click to expand)
-
Core Intuition: Divide the search space in half each iteration. It applies not just to sorted arrays, but to any monotonic feasibility function
$f(x)$ . -
Key Sub-Patterns:
-
Classic / Rotated Search: Compare
midagainst ends to identify which half is cleanly sorted. -
Binary Search on Answer Space: Guess an answer, verify with a greedy/linear check in
$O(N)$ , and adjustlowandhighbounds accordingly.
-
Classic / Rotated Search: Compare
-
Common Pitfalls: Integer overflow during midpoint calculation (use
low + (high - low) / 2), infinite loops caused by incorrectlow = midvslow = mid + 1.
π³ 7. Trees & Binary Search Trees (Click to expand)
- Core Intuition: Trees are recursive structures. Solve for left and right subtrees, then combine answers at the root.
-
Key Sub-Patterns:
- DFS (Pre-order, In-order, Post-order): Bottom-up info passing (height, diameter, balanced tree checks).
- BFS (Level Order): Queue-based traversal for shortest depth or view from top/side.
-
BST Invariant: Left
$< Node <$ Right. In-order traversal yields strictly sorted values.
-
Common Pitfalls: Forgetting the
root == nullbase case; assuming local BST condition implies global BST validity.
β°οΈ 8. Heap & Greedy (Click to expand)
- Core Intuition: When you need dynamic extrema (minimum or maximum) or local choices that lead to globally optimal solutions.
-
Key Sub-Patterns:
-
Top-K Elements: Maintain a Min-Heap of size
$K$ ; after iterating, the heap contains the$K$ largest items. - Two Heaps: Median finding using a Max-Heap for lower half and Min-Heap for upper half.
- Interval Greedy: Sort intervals by end time to maximize non-overlapping schedules.
-
Top-K Elements: Maintain a Min-Heap of size
-
Common Pitfalls: Forgetting that Java
PriorityQueueis a Min-Heap by default; greedy choice must be mathematically justifiable.
π§© 9. Backtracking (Click to expand)
- Core Intuition: Depth-first search through decision trees with the ability to undo choices (Choose $\to$ Explore $\to$ Un-choose).
-
Key Sub-Patterns:
-
Subsets: Decision whether to include
arr[i]or not. -
Permutations: Place unused elements into position; swap or use a
visitedboolean array. - Combinations / Partitioning: Iterate from current index to prevent duplicate orderings.
-
Subsets: Decision whether to include
-
Common Pitfalls: Not creating deep copies when saving states to result lists (
new ArrayList<>(current)); missing early pruning checks.
πΈοΈ 10. Graphs (Click to expand)
- Core Intuition: Represent entities as nodes and relationships as edges. Always determine whether the graph is directed, weighted, or cyclic.
- Key Sub-Patterns:
- BFS (Queue): Guaranteed shortest path in unweighted graphs.
- DFS (Recursion / Stack): Connected components, flood fill, cycle detection in directed graphs (3 colors: unvisited, visiting, visited).
- Topological Sort: Dependency resolution using Kahn's in-degree algorithm or DFS post-order.
- Disjoint Set Union (DSU): Dynamic connectivity and Kruskal's Minimum Spanning Tree.
- Common Pitfalls: Forgetting to mark nodes visited before pushing to the BFS queue, resulting in duplicate processing and infinite loops.
π§ 11. Dynamic Programming (Click to expand)
- Core Intuition: Break problems into subproblems with optimal substructure and overlapping calculations.
-
Key Sub-Patterns:
- 1D DP: Fibonacci, Climbing Stairs, House Robber ($dp[i] = \max(dp[i-1], dp[i-2] + val)$).
-
2D Grid DP: Unique paths, minimum path sum (
$dp[r][c] = \min(dp[r-1][c], dp[r][c-1]) + grid[r][c]$ ). - Knapsack Variations: 0/1 Knapsack (iterate backwards in 1D array) vs Unbounded Knapsack (iterate forwards).
- Longest Common Subsequence (LCS) / Edit Distance: String matching matrix.
- Common Pitfalls: Incorrect base cases, traversing loop orders incorrectly for state dependency.
Mastery comes from structured recall, not one-off solving. Use this proven retention cycle:
| Day Interval | Focus & Action | Outcome |
|---|---|---|
| π’ Day 1 | Solve 4β5 new problems in a single pattern module | Learn the pattern structure |
| π΅ Day 2 | Revise yesterday's solutions without looking at code | Solidify mental model |
| π‘ Day 4 | Re-solve problems that required hints or failed on edge cases | Fix conceptual gaps |
| π£ Day 7 | Solve 3 mixed problems across 2β3 previously studied patterns | Train pattern recognition speed |
| π Day 14 | Timed mock session (20 mins per Medium problem) | Build interview conditions |
| π΄ Day 30 | Revisit only historically weak topics and Hard questions | Long-term memory lock |
When tackling an unfamiliar question:
- 0 β 5 Minutes: Read problem statement, check constraints, trace inputs/outputs by hand.
- 5 β 10 Minutes: Write out brute force logic and calculate its time/space complexity.
- 10 β 15 Minutes: Pinpoint what work repeats and choose a pattern to eliminate it.
- If stuck after 15 minutes: Read only the Pattern or Approach section in the problem file, then close it and write the code entirely from your own mind.
Before running tests or clicking submit, verify:
[ ] 1. Have I verified empty input, single element, or null conditions?
[ ] 2. Are there duplicates in the input, and does my logic handle them?
[ ] 3. Could integer values overflow (e.g., mid calculation, large sums)?
[ ] 4. Are array bounds respected (index < 0 or index >= length)?
[ ] 5. Does the solution meet the target time complexity budget?
[ ] 6. Is auxiliary space optimal (can O(N) space be reduced to O(1))?
Each topic folder is cleanly organized by difficulty with dedicated problem notes:
500-DSA-Pattern-Problems/
βββ 01-Arrays/
β βββ Easy/ # Foundational questions
β βββ Medium/ # Core interview targets
β βββ Hard/ # Advanced bar-raisers
β βββ README.md # Module-specific problem index & links
βββ 02-Sliding-Window/
βββ 03-Strings-Hashing/
βββ 04-Linked-List/
βββ 05-Stack-Queue/
βββ 06-Binary-Search/
βββ 07-Trees-BST/
βββ 08-Heap-Greedy/
βββ 09-Backtracking/
βββ 10-Graphs/
βββ 11-Dynamic-Programming/
βββ README.md # Main Roadmap (You are here)Each problem file (.md) is structured consistently for optimal learning:
- π Direct LeetCode link
- π§© Underlying pattern category
- π‘ High-level approach intuition
- β±οΈ Exact Time and Space complexity
- β Complete, clean Java implementation
- π Concise line-by-line explanation
Copyright Β© 2026 Prem Kumar. All Rights Reserved.
This repository, including all source code, algorithms, solutions, documentation, roadmaps, diagrams, patterns, and curriculum structure, is proprietary and confidential. It is NOT open-source software and is not licensed under any permissive or copyleft license (such as MIT, Apache, GNU GPL, or AGPL).
- π All Rights Reserved: No permission is granted to copy, reproduce, modify, translate, distribute, sublicense, publish, sell, or commercialize this source code or substantial portions of it without prior written authorization from the copyright holder.
- ποΈ Viewing & Personal Study Only: You may view this repository and its contents solely for personal, individual learning and study. Viewing the source code on GitHub or via any public interface does not grant any license or right to reuse, copy, modify, or redistribute the materials.
- π« No Unauthorized Reuse: Commercial and non-commercial reuse, mirroring, inclusion in educational courseware or bootcamps, and scraping/ingestion into AI training datasets are strictly prohibited without prior written permission.
For full legal terms and licensing inquiries, please inspect the LICENSE file or contact Prem Kumar.