Pattern-based DSA practice in Java for product-based company interviews
This repo documents my consistent DSA journey in Java — structured around patterns, not just problems.
Every solution is:
- Written in clean, readable Java
- Commented with approach + time/space complexity
- Grouped by pattern for fast interview revision
💡 Core philosophy: Don't grind problems blindly. Recognize the pattern in 30 seconds, solve in 5 minutes.
| Folder | Status | Problems Solved | Patterns Covered |
|---|---|---|---|
| 📁 Arrays | 🟢 Active | 57 | HashMap, Two Pointers, Greedy, Prefix Sum, Kadane's, Cyclic Sort, Floyd Cycle, Intervals, Binary Search, Binary Search on Answer, Heap, Sliding Window, Partition, LCM+GCD, Frequency Array, Matrix Traversal, Array Traversal, Modular Arithmetic, Conditional Math |
| 📁 Strings | 🟢 Active | 24 | Two Pointers, Traverse from End, Sliding Window, Fixed Window, HashMap Grouping, String Matching, Expand Around Center, Simulation, Stack, DP on Strings, String Manipulation, Greedy |
| 📁 LinkedList | 🟢 Active | 6 | Reversal, Two Pointer Merge, Fast & Slow Pointers, Dummy Node, Two Pointer Sync |
| 📁 HashMap | ⚪ Upcoming | — | — |
| 📁 Stack | ⚪ Upcoming | — | — |
| 📁 Queue | ⚪ Upcoming | — | — |
| 📁 Trees | ⚪ Upcoming | — | — |
| 📁 Graphs | ⚪ Upcoming | — | — |
| 📁 Dynamic Programming | ⚪ Upcoming | — | — |
📌 Each folder has its own README with pattern-grouped problems, approach explanations, key templates, and common mistakes.
Arrays ████████████████████ 57/-- 🟢 Active
Strings ████████████████░░░░ 24/30+ 🟢 Active
LinkedList ██░░░░░░░░░░░░░░░░░░ 6/50+ 🟢 Active
HashMap ░░░░░░░░░░░░░░░░░░░░ 0/-- ⚪ Upcoming
Stack ░░░░░░░░░░░░░░░░░░░░ 0/-- ⚪ Upcoming
Queue ░░░░░░░░░░░░░░░░░░░░ 0/-- ⚪ Upcoming
Trees ░░░░░░░░░░░░░░░░░░░░ 0/-- ⚪ Upcoming
Graphs ░░░░░░░░░░░░░░░░░░░░ 0/-- ⚪ Upcoming
DP ░░░░░░░░░░░░░░░░░░░░ 0/-- ⚪ Upcoming
Total: 87 / 300+ problems ██████░░░░░░░░░░░░░░ 29%
| Pattern | Covered In | Status |
|---|---|---|
| HashMap & HashSet | Arrays, Strings | ✅ |
| Two Pointers | Arrays, Strings | ✅ |
| Greedy | Arrays, Strings | ✅ |
| Prefix Sum | Arrays | ✅ |
| Kadane's Algorithm | Arrays | ✅ |
| Cyclic Sort | Arrays | ✅ |
| Floyd's Cycle Detection | Arrays | ✅ |
| Interval Merge | Arrays | ✅ |
| Binary Search | Arrays | ✅ |
| Binary Search on Answer | Arrays | ✅ |
| Heap / Top K | Arrays | ✅ |
| Sliding Window | Arrays, Strings | ✅ |
| Partition (QuickSort) | Arrays | ✅ |
| LCM & GCD | Arrays | ✅ |
| Frequency Array | Arrays | ✅ |
| Matrix Traversal | Arrays | ✅ |
| Array Traversal — Max + Count | Arrays | ✅ |
| Modular Arithmetic | Arrays | ✅ |
| Conditional Math / Formula Derivation | Arrays | ✅ |
| Fixed-Size Sliding Window | Strings | ✅ |
| Expand Around Center | Strings | ✅ |
| Simulation / Parsing | Strings | ✅ |
| Stack (bracket matching, chain removal) | Strings | ✅ |
| DP on Strings | Strings | ✅ |
| String Manipulation | Strings | ✅ |
| Reversal (Linked List) | LinkedList | ✅ |
| Fast & Slow Pointers | LinkedList | ✅ |
| Two Pointer Merge | LinkedList | ✅ |
| Dummy Node | LinkedList | ✅ |
| Two Pointer Sync | LinkedList | ✅ |
| Recursion & Backtracking | — | 🔜 |
| BFS / DFS on Trees | — | 🔜 |
| Graph Algorithms | — | 🔜 |
| Advanced DP (2D, Knapsack) | — | 🔜 |
✅ Phase 1 — Arrays
└── HashMap · Two Pointers · Greedy · Prefix Sum · Kadane's
Cyclic Sort · Floyd Cycle · Binary Search · Intervals · Heap
Sliding Window · Partition · LCM+GCD · Frequency Array
Matrix Traversal · Array Traversal · Modular Arithmetic · Conditional Math
✅ Phase 2 — Strings
└── Two Pointers · Traverse from End · Sliding Window · Fixed Window
HashMap Grouping · String Matching · Expand Around Center
Simulation/Parsing · Stack · DP on Strings · String Manipulation · Greedy
🟢 Phase 3 — LinkedList (In Progress)
└── ✅ Reversal · ✅ Two Pointer Merge · ✅ Fast/Slow Pointers
✅ Dummy Node · ✅ Two Pointer Sync
⬜ Reversal II · ⬜ Fast/Slow Advanced · ⬜ Merge Advanced · ⬜ Recursion on Lists
⬜ Phase 4 — Stack + Queue
└── Monotonic Stack · Deque · Expression Evaluation · Sliding Window Maximum
⬜ Phase 5 — Trees + Recursion
└── DFS · BFS · Level Order · Path Sum · LCA · BST operations
⬜ Phase 6 — Graphs + BFS/DFS
└── Topological Sort · Union-Find · Dijkstra · Cycle Detection
⬜ Phase 7 — Dynamic Programming
└── 1D DP · 2D DP · Knapsack · LCS · Edit Distance · Palindrome DP
🔑 In an interview, identify the pattern first — then code.
| Trigger (What You See) | Pattern |
|---|---|
| Pair / target sum | HashMap |
| Frequency count, fast lookup | HashMap |
| Sorted array + pair or triplet | Two Pointers |
| Two sorted arrays, closest sum | Two Pointers (opposite ends) |
| Maximize profit, track running min/max | Greedy |
| Maximum contiguous subarray | Kadane's Algorithm |
| Subarray sum = k | Prefix Sum + HashMap |
| Zero-sum subarray | Prefix Sum + HashMap |
| Missing / duplicate in [1..n] | Cyclic Sort |
| Find duplicate, no extra space, no modify | Floyd's Cycle Detection |
| Overlapping ranges | Interval Merge |
| Sorted array, find element or peak | Binary Search |
| Minimize the maximum / threshold | Binary Search on Answer |
| Top K / Kth smallest / largest | Heap |
| Contiguous subarray, fixed window size | Sliding Window |
| Rearrange around pivot | Partition (QuickSort) |
| All of A divides X, X divides all of B | LCM + GCD |
| Count occurrences in small fixed range | Frequency Array |
| Square matrix, main + secondary diagonal | Matrix Traversal (index formula) |
| Largest element + count of occurrences | Array Traversal — Max + Count |
| Sum of all except one, min/max contribution | Total Sum ± min/max |
| Count pairs with sum divisible by k | Modular Arithmetic (remainders) |
| Round to nearest multiple, conditional rounding | Conditional Math (formula) |
| Minimum turns, can start from either end | Compute both directions, take min |
| Trigger (What You See) | Pattern |
|---|---|
| Reverse string in-place | Two Pointers (swap from ends) |
| Check palindrome, ignore special chars | Two Pointers + skip invalid |
| Last word / reverse words / trailing spaces | Traverse from End |
| Longest substring, no repeating chars | Sliding Window (variable) |
| Smallest window with all chars of t | Sliding Window + Frequency Map |
| Permutation of pattern / all anagrams | Fixed-Size Window + int[26] |
| Concatenation of equal-length words | Fixed-Size Window (chunked) |
| Group strings by same characters | HashMap Grouping (signature key) |
| Find first occurrence of pattern | String Matching (i <= n - m) |
| Longest palindromic substring | Expand Around Center |
| String to integer / validate format | Simulation / Parsing |
| Track movement up/down, count transitions | Simulation with state variable |
| Convert one format to another, edge cases | String Parsing + Conditional Handling |
| Shift/rotate characters cyclically | Character Arithmetic + Modulo |
| Longest valid bracket substring | Stack of Indices |
| Character number system with subtraction rules | Greedy (largest chunk first) |
| Repeating pattern, compare expected vs actual | Modulo-based Pattern Matching |
| Matching brackets / balanced pairs | Stack |
| Remove adjacent duplicates, chain reactions | Stack (push-pop) |
Pattern with * or . wildcards |
DP on Strings |
| Trigger (What You See) | Pattern |
|---|---|
| Reverse entire list / modify next pointers | Three-Pointer Reversal |
| Merge two sorted lists, pick smaller each step | Two Pointer Merge + Dummy Node |
| Remove duplicates from sorted list | Adjacent Comparison (no extra space) |
| Detect cycle / find middle / kth from end | Fast & Slow Pointers |
| Check if linked list is a palindrome | Fast & Slow + Reversal |
| Remove Nth node from end | Fast & Slow (gap of N+1) + Dummy |
| Delete nodes matching a value, head may change | Dummy Node + prev/curr pointers |
| Swap adjacent pairs without modifying values | Pointer Rewiring + Dummy Node |
| Find intersection of two lists, no extra space | Two Pointers + Head Switching |
| Company | Primary Patterns | Must-Know Problems |
|---|---|---|
| Amazon | HashMap, Greedy, Sliding Window | Two Sum, Best Time to Buy Stock, Longest Substring |
| Prefix Sum, Binary Search, DP | Subarray Sum = K, Min Window Substring, Regex Matching | |
| Microsoft | Arrays, Two Pointers, Intervals | Merge Intervals, Valid Palindrome, 3Sum |
| Meta | Two Pointers, HashMap, Graphs | Remove Duplicates, Group Anagrams, Find All Anagrams |
| Adobe | Sorting, Strings, Simulation | Valid Number, Longest Palindrome, atoi |
| Flipkart | Greedy, Binary Search, Kadane's | Product Except Self, Koko Bananas, Max Subarray |
| Mode | What to Do |
|---|---|
| 📖 Learn | Open the topic folder → read the pattern README → solve problems group by group |
| 🔁 Revise | Read only the cheat sheet above + key templates in each folder README |
| ⚡ Interview Prep | Cheat sheet only — identify pattern in ≤ 30 seconds, then code from template |
Daily target: 3 problems/day — one pattern group at a time. Don't jump between topics.
Weekly review: Re-attempt hard problems without notes. Timed: 20 minutes each.
⭐ Star this repo if it helps you. Keep solving. Keep growing. 🚀