GitHub - rahul22mrk/DSA-Interview-Notes-Java: ๐งฉ Pattern-based DSA Interview Notes in Java | 398 Problems ยท 16 Patterns | Approach-first thinking with reusable templates | Easy โ Hard | MAANG-ready
Pattern-wise DSA prep ยท Interview-focused ยท Clean Java templates ยท MAANG-ready
| ๐ข Easy | ๐ก Medium | ๐ด Hard | Total |
|---|---|---|---|
| 90 | 236 | 72 | 398 |
๐ Table of Contents
| Section | |
|---|---|
| ๐งฉ | Patterns Covered (16 patterns) |
| ๐ | Problems Index (398 problems) |
| โก | Quick Clue Detector |
| ๐ | Repository Structure |
| ๐ | How to Use |
| ๐ | Resources |
๐งฉ Patterns Covered
Each pattern โ notes file (theory + templates) + problems file (solved problems with approach tables + examples).
โ Two Pointers
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_two_pointers_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_two_pointers_problems.md | Both-ends โ Sum (2Sum, 3Sum, 4Sum) | Pair with Target, 3Sum, 3Sum Closest, Triplets Smaller Sum, 4Sum | Easy โ Medium |
| 02_two_pointers_problems.md | Both-ends โ Reverse / Palindrome | Valid Palindrome, Reverse Vowels, Squares of Sorted Array | Easy |
| 02_two_pointers_problems.md | Same Direction โ In-place Modify | Remove Duplicates, Rearrange 0s & 1s, Backspace Compare | Easy โ Medium |
| 02_two_pointers_problems.md | Dutch National Flag (3-pointer) | Sort Colors | Medium |
| 02_two_pointers_problems.md | Two Arrays | Merge Sorted Array, Is Subsequence | Easy |
| 02_two_pointers_problems.md | Trapping Water / FAANG | Trapping Rain Water, Container with Most Water, Min Window Sort | Medium โ Hard |
| 03_two_pointers_extended.md | Extended Classification + Pseudocode | 60+ problems grouped by sub-pattern with approach skeleton | Easy โ Hard |
โ Prefix Sum
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_prefix_sum_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_prefix_sum_problems.md | Basic Prefix Array | Range Sum Query, Find Pivot Index | Easy |
| 02_prefix_sum_problems.md | HashMap โ Count / Existence | Subarray Sum Equals K, Contiguous Array, Longest Subarray Sum K | Medium |
| 02_prefix_sum_problems.md | Modulo HashMap | Subarray Sums Divisible by K, Continuous Subarray Sum | Medium |
| 02_prefix_sum_problems.md | 2D Prefix Sum | Range Sum Query 2D, Max Sum Rectangle โค K | Medium โ Hard |
| 02_prefix_sum_problems.md | Hard (Deque / Merge Sort) | Shortest Subarray Sum โฅ K, Count of Range Sum | Hard |
| 02_prefix_sum_problems.md | Bonus / FAANG | Maximum Product Subarray | Medium |
โ Sliding Window
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_sliding_window_pattern_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_sliding_window_pattern_problems.md | Fixed Window | Max Sum K, Max Average, Permutation in String, Find All Anagrams | Easy โ Medium |
| 02_sliding_window_pattern_problems.md | Variable Window โ Maximize | No-Repeat, K Distinct, Fruits/Baskets, Longest Replacement, Max Ones III, Delete One, Budget Substring | Medium โ Hard |
| 02_sliding_window_pattern_problems.md | Variable Window โ Minimize | Min Size Subarray Sum, Min Window Substring, Product Less Than K | Medium โ Hard |
| 02_sliding_window_pattern_problems.md | At-Most to Exact (Count) | K Different Integers, Binary Subarrays Sum, Nice Subarrays | Medium โ Hard |
| 02_sliding_window_pattern_problems.md | FAANG Hard | Words Concatenation, Max Freq Element, Exam Confusion, Min Ops Continuous | Medium โ Hard |
โ Merge Intervals
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_merge_interval_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_merge_interval_problems.md | Core Merge / Insert | Merge Intervals, Insert Interval | Medium |
| 02_merge_interval_problems.md | Intersection / Overlap Detection | Interval List Intersections, Overlapping Intervals Check | Medium |
| 02_merge_interval_problems.md | Resource Scheduling (Heap) | Min Meeting Rooms, Max CPU Load, Task Scheduler | Medium โ Hard |
| 02_merge_interval_problems.md | Greedy (Sort by End) | Non-overlapping Intervals, Min Arrows, Meeting Scheduler | Medium |
| 02_merge_interval_problems.md | Hard / FAANG | Employee Free Time, Remove Covered Intervals, Data Stream Intervals | Hard |
โ Kadane's Algorithm
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_kadane_pattern_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_kadane_pattern_problems.md | Classic Kadane (Sum) | Max Subarray Sum, Min Subarray Sum, Circular Max Sum | Easy โ Medium |
| 02_kadane_pattern_problems.md | Product Kadane | Max Product Subarray, Max Absolute Sum | Medium |
| 02_kadane_pattern_problems.md | Kadane + Stock / DP | Buy & Sell Stock, House Robber, Longest Positive Sum | Easy โ Medium |
| 02_kadane_pattern_problems.md | Kadane with State | Max Sum with One Deletion, Alternating Subarray Sum | Medium |
| 02_kadane_pattern_problems.md | 2D Kadane | Max Sum Rectangle in Matrix, Max Sum Submatrix โค K | Hard |
โ Cyclic Sort
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_cyclic_sort_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_cyclic_sort_problems.md | Core Cyclic Sort | Cyclic Sort | Easy |
| 02_cyclic_sort_problems.md | Find Missing | Missing Number, All Missing Numbers, Smallest Missing Positive, First K Missing | Easy โ Hard |
| 02_cyclic_sort_problems.md | Find Duplicate | Find Duplicate Number, All Duplicate Numbers | Easy โ Medium |
| 02_cyclic_sort_problems.md | Combined Missing + Duplicate | Corrupt Pair, Set Mismatch | Easy |
| 02_cyclic_sort_problems.md | FAANG / Hard | Missing Number (XOR/Math), Disappeared Numbers, First Missing Positive | Easy โ Hard |
โ Binary Search
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_binary_search_pattern_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_binary_search_pattern_problems.md | Basic Binary Search | Binary Search, Upper Bound, First/Last Position, Count Occurrences, Infinite Array | Easy โ Medium |
| 02_binary_search_pattern_problems.md | Bitonic Array Search | Peak Index, Search in Bitonic Array, Find Peak Element | Easy โ Medium |
| 02_binary_search_pattern_problems.md | Range Search | Min in Rotated, Count Rotations, Search Rotated, Rotated with Duplicates, Single Element | Medium โ Hard |
| 02_binary_search_pattern_problems.md | Allocate Problems (BS on Answer) | Koko, Ship Packages, Book Allocation, Split Array, Aggressive Cows, Bouquets, Candies, H-Index | Medium โ Hard |
| 02_binary_search_pattern_problems.md | Counting / Kth Element | 2D Matrix I & II, Kth Smallest Matrix, Multiplication Table, Median Two Arrays, Kth Missing | Medium โ Hard |
| 02_binary_search_pattern_problems.md | FAANG Extras | Time Based KV Store, K Closest Elements, Min Speed, Max Gas Station Distance | Medium โ Hard |
โ Slow & Fast Pointers (Floyd's Algorithm)
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_slow_fast_pointers_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_slow_fast_pointers_problems.md | Classic Floyd's โ Cycle Detection | LinkedList Cycle, Start of LinkedList Cycle, Circular Array Loop | Easy โ Hard |
| 02_slow_fast_pointers_problems.md | Find Middle + Process | Middle of LinkedList, Palindrome LinkedList, Reorder List | Easy โ Medium |
| 02_slow_fast_pointers_problems.md | Gap Technique | Remove Nth Node From End, Odd Even Linked List | Medium |
| 02_slow_fast_pointers_problems.md | Implicit Cycle | Happy Number, Find the Duplicate Number | Medium |
| 02_slow_fast_pointers_problems.md | Slow Write / Fast Read | String Compression, Remove Duplicates I & II, Duplicate Zeros | Easy โ Medium |
| 02_slow_fast_pointers_problems.md | Rotate / Split + Reconnect | Rotate List, Rotate Array | Medium |
| 02_slow_fast_pointers_problems.md | Two-pointer String / Array | Partition Labels, Counting Binary Substrings, Last Substring | Easy โ Hard |
| 02_slow_fast_pointers_problems.md | Bonus / FAANG | Intersection of Two Lists, Sort List, Bounded Max Subarrays, K-diff Pairs | Easy โ Medium |
โ Stack
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_stack_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_stack_problems.md | Monotonic Stack | NGE I/II, Daily Temps, Stock Span, Largest Rectangle, Trapping Rain Water, Sum Subarray Mins, Remove Nodes LL | Easy โ Hard |
| 02_stack_problems.md | Bracket / Parentheses | Valid Parentheses, Min Remove Valid, Longest Valid Parens, Score of Parentheses | Easy โ Hard |
| 02_stack_problems.md | Stack + Count / Removal | Remove Adjacent I & II, Backspace, Remove Stars, Remove Duplicate Letters, Remove K Digits | Easy โ Hard |
| 02_stack_problems.md | Expression Evaluation | Evaluate RPN, Basic Calculator II, Basic Calculator, Decode String | Medium โ Hard |
| 02_stack_problems.md | Stack Simulation | Simplify Path, Asteroid Collision, Baseball Game, Reverse String | Easy โ Medium |
| 02_stack_problems.md | Design Problems | Min Stack, Queue via Stacks, Stack via Queues, Browser History, Max Freq Stack | Easy โ Hard |
โ HashMap
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_hashmap_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_hashmap_problems.md | Frequency Count | Valid Anagram, First Non-Repeating, Max Balloons, Longest Palindrome, Ransom Note, Top K Frequent | Easy โ Medium |
| 02_hashmap_problems.md | Complement Lookup | Two Sum | Easy |
| 02_hashmap_problems.md | Prefix Sum | Subarray Sum = K | Medium |
| 02_hashmap_problems.md | Grouping / Bucketing | Group Anagrams | Medium |
| 02_hashmap_problems.md | Index Tracking + Sliding Window | Longest Substring Without Repeating | Medium |
| 02_hashmap_problems.md | Two-Map Bidirectional | Isomorphic Strings, Word Pattern | Easy |
| 02_hashmap_problems.md | HashSet Membership | Jewels & Stones, Contains Duplicate II, Longest Consecutive Sequence | Easy โ Medium |
| 02_hashmap_problems.md | Design (LRU Cache) | LRU Cache | Medium |
โ In-Place Reversal of a LinkedList
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_inplace_reversal_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_inplace_reversal_problems.md | Full Reversal | Reverse a LinkedList | Easy |
| 02_inplace_reversal_problems.md | Partial / Sub-list Reversal | Reverse a Sub-list [p,q] | Medium |
| 02_inplace_reversal_problems.md | K-Group Reversal | Reverse in Pairs, Reverse K-Group, Reverse Alternate K | Medium โ Hard |
| 02_inplace_reversal_problems.md | Conditional Reversal | Reverse Nodes in Even Length Groups | Hard |
| 02_inplace_reversal_problems.md | Rotation / Reconnect | Rotate a LinkedList | Medium |
| 02_inplace_reversal_problems.md | Reversal as a Tool | Palindrome LL, Reorder List, Sort List | Easy โ Medium |
| 02_inplace_reversal_problems.md | FAANG / Hard | Remove Nth, Add Two Numbers, Copy Random Pointer, Merge Two Sorted | Easy โ Medium |
โ Heap / Priority Queue
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_heap_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_heap_problems.md | Kth Element | Kth Largest Array, Kth Smallest Matrix, Kth Largest Stream, Kth Weakest Row | Easy โ Medium |
| 02_heap_problems.md | Top K | Top K Frequent Elements/Words, Sort by Freq, K Closest Points/Elements | Easy โ Medium |
| 02_heap_problems.md | Merge K Lists / Arrays | Merge K Lists, Merge K Arrays, K Pairs Smallest Sums, Smallest Range K Lists | Medium โ Hard |
| 02_heap_problems.md | Two Heaps (Median) | Find Median from Stream, Sliding Window Median | Hard |
| 02_heap_problems.md | Greedy + Heap | Task Scheduler, Reorganize String, Last Stone Weight, IPO, Course Schedule III, Min Refuel Stops | Medium โ Hard |
| 02_heap_problems.md | Design Problems | Design Twitter, Food Rating System, Distant Barcodes | Medium |
โ Recursion & Backtracking
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_recursion_backtracking_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_recursion_backtracking_problems.md | Basic Recursive Functions | Fibonacci, Palindrome Check, Array Sorted, Sum Digits, Remove Char, Count Good Numbers | Easy โ Medium |
| 02_recursion_backtracking_problems.md | Divide & Conquer | Pow(x,n), Binary Search, Merge Sort, Max Subarray, Count Smaller, Reverse Pairs, Count Range Sum | Easy โ Hard |
| 02_recursion_backtracking_problems.md | Backtracking (Classic) | Subsets I/II, Permutations I/II, Combinations, Combination Sum I/II, Generate Parens, Phone Letters, Palindrome Partition | Medium |
| 02_recursion_backtracking_problems.md | Backtracking (Hard / Grid) | N-Queens, Word Search, Sudoku Solver, Unique Paths III, Path with Max Gold | Medium โ Hard |
| 02_recursion_backtracking_problems.md | Recursive Search | Jump Game | Medium |
โ Trees
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_tree_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_tree_problems.md | Traversal | Inorder, Preorder, Postorder, Level Order, Zigzag, Level Order II | Easy โ Medium |
| 02_tree_problems.md | Mirror & Symmetry | Invert Tree, Symmetric Tree, Same Tree, Subtree, Flip Equivalent | Easy โ Medium |
| 02_tree_problems.md | Traversal & Search (BST) | Search BST, LCA BST, LCA Binary Tree, LCA Deepest Leaves, Find Mode, Two Sum IV, Kth Smallest | Easy โ Medium |
| 02_tree_problems.md | Validation & Properties | Min/Max Depth, Balanced, Diameter, Tilt, Completeness, Validate BST, Recover BST | Easy โ Hard |
| 02_tree_problems.md | Path Sum & Root to Leaf | Path Sum I/II/III, Sum Root to Leaf, Max Path Sum | Easy โ Hard |
| 02_tree_problems.md | Construction | Construct from Traversals (3 variants), Sorted Array/List to BST, Max BT, Construct BST from Preorder, Serialize/Deserialize | Medium โ Hard |
| 02_tree_problems.md | Extended BFS | Even Odd Tree, Reverse Odd Levels, Deepest Leaves Sum, Add One Row, Max Width, Distance K | Medium |
| 02_tree_problems.md | Extended Root to Leaf | Binary Tree Paths, Smallest String Leaf, Insufficient Nodes, Pseudo-Palindromic Paths | Easy โ Medium |
| 02_tree_problems.md | Extended Ancestor & BST | Max Diff Node Ancestor, Kth Ancestor, Range Sum BST, Min Abs Diff BST, Insert BST | Easy โ Hard |
| tree_traversal.md | Traversal Quick Reference | DFS Iterative/Recursive, BFS, Side Views (Left/Right/Top/Bottom), Boundary | Reference |
| tree_traversal.md | Traversal Quick Revision | DFS Iterative/Recursive, BFS, Side Views (Left/Right/Top/Bottom), Boundary Traversal | Reference |
โ Graph
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_graph_notes.md | Identification + All Algorithm Templates + Cheatsheet | โ | Reference |
| 02_graph_problems.md | BFS / DFS / Grid | Number of Islands, Friend Circles, Max Area, Surrounded Regions, Shortest Path Binary Matrix, Word Ladder, Path Min Effort, Swim in Water, Find Safe States, All Paths, Longest Increasing Path | Easy โ Hard |
| 02_graph_problems.md | Shortest Path (Dijkstra / BF / Floyd) | Network Delay Time, Cheapest Flights K Stops, Path Max Probability, Min Cost Reach Destination, Find City | Medium โ Hard |
| 02_graph_problems.md | Topological Sort | Course Schedule I/II/IV, Alien Dictionary, Sequence Reconstruction, Strange Printer II | Medium โ Hard |
| 02_graph_problems.md | Union Find | Redundant Connection I/II, Accounts Merge, Network Connected, Equality Equations, Min Cost Connect Points | Medium โ Hard |
| 02_graph_problems.md | Bipartite / Graph Coloring | Is Graph Bipartite, Possible Bipartition, Flower Planting, M-Coloring | Easy โ Medium |
| 02_graph_problems.md | MST (Kruskal / Prim) | Min Cost Connect Points, Connecting Cities, Min Cost Water, Connect Sticks | Medium โ Hard |
| 03_graph_beginners_problems.md | Beginners Guide โ 30 Solved Problems | All patterns with approach table + code + dry run | Easy โ Medium |
| 04_graph_algorithms_quick_revision.md | Quick Revision โ Dijkstra, BF, Floyd, Prim, Kruskal, DSU | Full Java implementations for interview revision | Medium โ Hard |
โ Dynamic Programming
| File | Sub-Pattern | Problems | Difficulty |
|---|---|---|---|
| 01_dp_notes.md | Identification + Templates + Cheatsheet | โ | Reference |
| 02_dp_problems.md | Fibonacci / Decision Making | House Robber, Maximum Subarray, Decode Ways | Easy โ Medium |
| 02_dp_problems.md | Min/Max Path to Target | Coin Change, Min Path Sum, Min Falling Path Sum, Unique Paths | Medium |
| 02_dp_problems.md | 0/1 Knapsack | 0/1 Knapsack, Partition Equal Subset Sum, Target Sum, Ones and Zeroes, Last Stone Weight II | Medium |
| 02_dp_problems.md | Unbounded Knapsack | Coin Change II, Count Numbers with Unique Digits | Medium |
| 02_dp_problems.md | LIS / Subsequences | LIS, Count Palindromic Subsequences | Medium โ Hard |
| 02_dp_problems.md | DP on Strings | LCS, Edit Distance, LPS, Distinct Subsequences | Medium โ Hard |
| 02_dp_problems.md | Interval DP | Burst Balloons, Min Cost Cut Stick, MCM, Strange Printer, Merge Stones, Remove Boxes | Hard |
| 02_dp_problems.md | Probability / Expectation DP | Knight Probability, Dice Roll Simulation, Soup Servings, New 21 Game | Medium |
| 03_dp_patterns_level1.md | Level 1 Extended (48 problems) | Stocks, Grid DP, All Knapsack variants, All LCS/LIS variants | Easy โ Hard |
| 04_dp_patterns_level2.md | Level 2 Advanced (30 problems) | Interval DP, Tree DP, Digit DP, Bitmask DP, Probability DP | Hard |
๐ Coming Soon
| Folder | Pattern | Key Topics |
|---|---|---|
17_Trie_Pattern |
Trie | Insert/Search/Delete, Word search II, Auto-complete, Replace words |
18_Bit_Manipulation_Pattern |
Bit Manipulation | XOR tricks, Count bits, Power of two, Subsets via bits, Single number |
๐ Problems Index
Full sortable list โ PROBLEMS_INDEX.md
๐ Problems by Pattern โ click to expand
| Pattern | Total | ๐ข Easy | ๐ก Medium | ๐ด Hard |
|---|---|---|---|---|
| ๐ฒ Tree | 54 | 20 | 29 | 5 |
| ๐ธ๏ธ Graph | 44 | 2 | 32 | 10 |
| ๐งฎ Dynamic Programming | 38 | 3 | 26 | 9 |
| ๐ Binary Search | 32 | 8 | 18 | 6 |
| ๐ Stack | 32 | 7 | 18 | 7 |
| โฐ๏ธ Heap / Priority Queue | 25 | 5 | 14 | 6 |
| ๐ Slow & Fast Pointers | 23 | 6 | 17 | 0 |
| ๐ช Sliding Window | 21 | 2 | 17 | 2 |
| ๐ Two Pointers | 20 | 8 | 10 | 2 |
| ๐บ๏ธ HashMap | 16 | 8 | 7 | 1 |
| โฉ๏ธ Backtracking | 16 | 0 | 11 | 5 |
| ๐ In-Place Reversal | 14 | 3 | 10 | 1 |
| โฉ๏ธ Recursion | 13 | 5 | 6 | 2 |
| ๐ Merge Intervals | 13 | 1 | 9 | 3 |
| โ Prefix Sum | 12 | 2 | 7 | 3 |
| ๐ Kadane | 12 | 2 | 7 | 3 |
| ๐ Cyclic Sort | 12 | 6 | 3 | 3 |
| Total | 398 | 90 | 236 | 72 |
๐ข First 50 Problems โ click to expand
| # | Problem | LC# | Pattern | Diff |
|---|---|---|---|---|
| 1 | Pair with Target Sum (2Sum II) | 167 | Two Pointers | ๐ข |
| 2 | Remove Duplicates from Sorted Array | 26 | Two Pointers | ๐ข |
| 3 | Squaring a Sorted Array | 977 | Two Pointers | ๐ข |
| 4 | Triplet Sum to Zero (3Sum) | 15 | Two Pointers | ๐ก |
| 5 | Triplet Sum Close to Target | 16 | Two Pointers | ๐ก |
| 6 | Dutch National Flag (Sort Colors) | 75 | Two Pointers | ๐ก |
| 7 | Backspace String Compare | 844 | Two Pointers | ๐ข |
| 8 | Trapping Rain Water | 42 | Two Pointers | ๐ด |
| 9 | Container With Most Water | 11 | Two Pointers | ๐ก |
| 10 | 4Sum | 18 | Two Pointers | ๐ก |
| 11 | Max Sum Subarray of Size K | โ | Sliding Window | ๐ข |
| 12 | Smallest Subarray with Sum โฅ S | 209 | Sliding Window | ๐ก |
| 13 | Longest Substring with K Distinct | 340 | Sliding Window | ๐ก |
| 14 | Minimum Window Substring | 76 | Sliding Window | ๐ด |
| 15 | Find All Anagrams in a String | 438 | Sliding Window | ๐ก |
| 16 | Sliding Window Maximum | 239 | Sliding Window | ๐ด |
| 17 | Linked List Cycle | 141 | Slow & Fast | ๐ข |
| 18 | Cycle Start | 142 | Slow & Fast | ๐ก |
| 19 | Happy Number | 202 | Slow & Fast | ๐ข |
| 20 | Middle of Linked List | 876 | Slow & Fast | ๐ข |
| 21 | Find Duplicate Number (Floyd) | 287 | Slow & Fast | ๐ก |
| 22 | Max Sum Subarray (Kadane) | 53 | Kadane | ๐ข |
| 23 | Best Time to Buy Stock I | 121 | Kadane | ๐ข |
| 24 | Best Time II (unlimited) | 122 | Kadane | ๐ก |
| 25 | Best Time III (2 transactions) | 123 | Kadane | ๐ด |
| 26 | Best Time IV (k transactions) | 188 | Kadane | ๐ด |
| 27 | Range Sum Query - Immutable | 303 | Prefix Sum | ๐ข |
| 28 | Subarray Sum Equals K | 560 | Prefix Sum | ๐ก |
| 29 | Subarray Sums Divisible by K | 974 | Prefix Sum | ๐ก |
| 30 | Merge Intervals | 56 | Merge Interval | ๐ก |
| 31 | Insert Interval | 57 | Merge Interval | ๐ก |
| 32 | Minimum Meeting Rooms | 253 | Merge Interval | ๐ด |
| 33 | Employee Free Time | 759 | Merge Interval | ๐ด |
| 34 | Next Greater Element I | 496 | Stack | ๐ข |
| 35 | Daily Temperatures | 739 | Stack | ๐ก |
| 36 | Largest Rectangle in Histogram | 84 | Stack | ๐ด |
| 37 | Valid Parentheses | 20 | Stack | ๐ข |
| 38 | Min Stack | 155 | Stack | ๐ก |
| 39 | Two Sum | 1 | HashMap | ๐ข |
| 40 | Group Anagrams | 49 | HashMap | ๐ก |
| 41 | LRU Cache | 146 | HashMap | ๐ก |
| 42 | Reverse a LinkedList | 206 | In-Place Reversal | ๐ข |
| 43 | Reverse K-Group | 25 | In-Place Reversal | ๐ด |
| 44 | Binary Search | 704 | Binary Search | ๐ข |
| 45 | Search in Rotated Array | 33 | Binary Search | ๐ก |
| 46 | Median of Two Sorted Arrays | 4 | Binary Search | ๐ด |
| 47 | Cyclic Sort | โ | Cyclic Sort | ๐ข |
| 48 | Find the Missing Number | 268 | Cyclic Sort | ๐ข |
| 49 | Find the Duplicate Number | 287 | Cyclic Sort | ๐ก |
| 50 | First Missing Positive | 41 | Cyclic Sort | ๐ด |
๐ Full 398 problems โ PROBLEMS_INDEX.md
โก Quick Clue Detector
Read the problem โ spot these keywords โ know the pattern instantly.
๐ Two Pointers
| If you see this... | Pattern |
|---|---|
"find pair/triplet with sum" |
Both-ends โ start from both sides |
"remove duplicates in-place" |
Same-direction โ fast pointer skips |
"partition around pivot" |
Dutch flag โ three-pointer |
"sorted array, maximize/minimize" |
Both-ends sweep |
"in-place O(1) space" |
Pointer manipulation, no extra array |
๐ช Sliding Window
| If you see this... | Pattern |
|---|---|
"longest/shortest subarray with condition" |
Variable window โ shrink when violated |
"subarray of fixed size k" |
Fixed window โ slide by 1 |
"at most k distinct characters" |
Frequency map + shrink when > k |
"minimum window containing all" |
Variable โ expand then shrink |
"all anagrams / permutations in string" |
Fixed window + frequency compare |
๐บ๏ธ HashMap
| If you see this... | Pattern |
|---|---|
"two numbers that sum to target" |
Complement lookup โ containsKey(target-x) |
"count occurrences / frequency" |
Frequency map โ getOrDefault(x,0)+1 |
"group / classify / anagram" |
Bucketing โ computeIfAbsent(key, ...) |
"subarray with sum k" |
Prefix sum map โ put(0,1); get(prefix-k) |
"isomorphic / pattern match" |
Two-map bidirectional |
"LRU cache / evict least recently used" |
LinkedHashMap or HashMap + DLL |
๐ Binary Search
| If you see this... | Pattern |
|---|---|
"sorted array, find target" |
Classic lo+(hi-lo)/2 |
"rotated sorted array" |
Find pivot, search correct half |
"find minimum in rotated" |
Check which half is sorted |
"minimize max / maximize min" |
Binary search on answer + feasibility check |
"first/last position of element" |
lo=mid+1 or hi=mid variant |
๐งฎ Dynamic Programming
| If you see this... | Pattern |
|---|---|
"max/min way to reach target" |
Min/Max path โ dp[i]=best(dp[i-way]+cost) |
"count ways / how many ways" |
Counting DP โ dp[i]+=dp[i-way], dp[0]=1 |
"each item used at most once" |
0/1 Knapsack โ REVERSE capacity loop |
"items reusable / unlimited supply" |
Unbounded Knapsack โ FORWARD loop |
"two strings โ match / edit / common" |
2D dp[i][j] on strings |
"longest increasing subsequence" |
LIS โ dp[i]=max(dp[j]+1) or O(n log n) |
"split interval [i..j] at point k" |
Interval DP โ loop by LENGTH then k |
"buy/sell stock with cooldown/fee" |
State machine โ hold/notHold states |
๐ฒ Trees
| If you see this... | Pattern |
|---|---|
"inorder/preorder/postorder" |
DFS โ recursive or iterative with stack |
"level order / BFS" |
BFS โ queue + snapshot size=q.size() |
"lowest common ancestor" |
Post-order โ both sides non-null โ LCA |
"path sum root to leaf" |
Top-down DFS โ pass remaining sum |
"maximum path sum any node" |
Bottom-up + global max โ ignore negatives |
"validate BST" |
Top-down bounds โ pass (min,max) as Long |
"construct tree from traversals" |
Divide & conquer โ HashMap for inorder index |
๐ธ๏ธ Graph
| If you see this... | Pattern |
|---|---|
"islands / connected components" |
BFS or DFS flood fill |
"shortest path unweighted" |
BFS โ level = distance |
"shortest path weighted" |
Dijkstra (non-negative) or Bellman-Ford |
"cycle detection directed graph" |
DFS with WHITE/GRAY/BLACK coloring |
"topological sort / course schedule" |
Kahn's BFS (in-degree) or DFS post-order |
"union find / connected groups" |
DSU with path compression + union by rank |
"minimum spanning tree" |
Kruskal (sort edges) or Prim (min-heap) |
โฐ๏ธ Heap / Priority Queue
| If you see this... | Pattern |
|---|---|
"Kth largest / smallest" |
Min-heap size k โ peek() = kth largest |
"top K frequent / closest" |
Freq/dist map + min-heap size k |
"merge K sorted lists/arrays" |
Min-heap as pointer โ (val, listIdx, elemIdx) |
"find median from stream" |
Two heaps โ maxHeap(lower) + minHeap(upper) |
"task scheduler / reorganize string" |
Max-heap by frequency, greedy alternation |
๐ Stack ยท โฉ๏ธ Backtracking ยท ๐ In-Place Reversal ยท ๐ Cyclic Sort ยท ๐ข Slow & Fast ยท โ Prefix Sum
๐ Stack (Monotonic)
| If you see this... | Pattern |
|---|---|
"next greater / smaller element" |
Monotonic stack โ push; pop when condition met |
"valid parentheses / brackets" |
Push open; pop on close; check match |
"largest rectangle / trapped water" |
Monotonic stack โ area calc on pop |
"remove k digits / smallest number" |
Monotonic stack with removal limit |
โฉ๏ธ Backtracking
| If you see this... | Pattern |
|---|---|
"all subsets / power set" |
Add at every level; pass i+1 |
"all permutations" |
used[] array; add at leaf (size==n) |
"combinations summing to target" |
Pass i for reuse; prune remain<0 |
"duplicates in input, unique results" |
Sort + if(i>start && nums[i]==nums[i-1]) skip |
"N-Queens / Sudoku / Word Search" |
Place + isValid + recurse + undo |
๐ In-Place Reversal
| If you see this... | Pattern |
|---|---|
"reverse a linked list" |
4-line flip: save next โ flip โ advance prev โ advance curr |
"reverse every k nodes" |
K-group โ check k exist, reverse, reconnect |
"rotate a linked list by k" |
Find tail+len, k%=len, reconnect |
๐ Cyclic Sort
| If you see this... | Pattern |
|---|---|
"array of n integers in range [1, n]" |
Place each number at index nums[i]-1 |
"find the missing / duplicate number" |
Cyclic sort โ scan for nums[i]!=i+1 |
"smallest missing positive" |
Cyclic sort with range guard [1,n] |
๐ข Slow & Fast Pointers
| If you see this... | Pattern |
|---|---|
"detect cycle in linked list" |
Floyd's โ slow+1, fast+2 |
"find middle of linked list" |
Slow stops at middle when fast reaches end |
"find start of cycle" |
Reset slow to head after meeting; both move by 1 |
โ Prefix Sum
| If you see this... | Pattern |
|---|---|
"subarray sum equals k" |
Prefix map โ put(0,1) then get(prefix-k) |
"range sum query" |
Build prefix array, answer in O(1) |
"contiguous array equal 0s and 1s" |
Remap 0โ-1, find longest subarray sum=0 |
๐ Repository Structure
DSA-Interview-Notes-Java/
โโโ 01_Two_Pointers_Patterns/ โโโ 01_two_pointers_notes.md
โ โโโ 02_two_pointers_problems.md
โ โโโ 03_two_pointers_extended.md
โโโ 02_Sliding_Window_Patterns/ โโโ notes + problems
โโโ 03_Slow_And_Fast_Pointers_Pattern/
โโโ 04_Kadane_Pattern/
โโโ 05_Prefix_Sum_Pattern/
โโโ 06_Merge_Interval_Pattern/
โโโ 07_Stack_Pattern/
โโโ 08_HashMap_Pattern/
โโโ 09_In-Place_Reversal_LinkedList/
โโโ 10_Binary_Search_Pattern/
โโโ 11_Cyclic_Sort_Pattern/
โโโ 12_Heap_Pattern/
โโโ 13_Recursion_And_Backtracking/
โโโ 14_Trees_Pattern/ โโโ notes + problems + tree_traversal.md
โโโ 15_Graph_Pattern/ โโโ notes + problems + beginners + algorithms
โโโ 16_Dynamic_Programming_Pattern/ โโโ notes + problems + level1 + level2
โโโ 17_Trie_Pattern/ ๐ coming soon
โโโ 18_Bit_Manipulation_Pattern/ ๐ coming soon
โโโ PROBLEMS_INDEX.md โ All 398 problems grouped by pattern
โโโ README.md
๐ How to Use
- Read notes first โ
01_*_notes.mdsections 1โ4 (Identify, What is it, Core rules, Framework) - Attempt blind โ Try each problem 15โ20 min before looking at solution
- Study approach table โ Understand each step, not just the code
- Re-implement from memory โ Write code from scratch, then check
- Pre-interview revision โ Section 7 (cheatsheet) in every notes file
Pattern Priority:
| Priority | Patterns |
|---|---|
| ๐ฅ Master first | Two Pointers ยท Sliding Window ยท HashMap ยท Binary Search ยท Tree DFS/BFS ยท DP |
| โก Important | Heap ยท Graph ยท Backtracking ยท Merge Intervals ยท Monotonic Stack |
| โ Good to have | Cyclic Sort ยท Prefix Sum ยท Slow/Fast Pointers |
๐ Note Format
01_*_notes.md 02_*_problems.md
โโโ 1. How to identify โโโ Each problem:
โโโ 2. What is it โโโ Approach table
โโโ 3. Core rules โโโ Java code
โโโ 4. 2-Question framework โโโ Traced example
โโโ 5. Variants table
โโโ 6. Java template
โโโ 7. Cheatsheet โ pre-interview revision
โโโ 8. Common mistakes
โโโ 9. Complexity
๐ Resources
| Resource | What it covers |
|---|---|
| DSA Patterns you need to know | Master pattern list |
| Dynamic Programming Patterns | DP Part I |
| Dynamic Programming Patterns II | DP Part II |
| Ultimate Binary Search Template | One template solves all |
| Graph For Beginners | BFS, DFS, Union Find |
| Backtracking General Approach | Subsets, Perms, Combinations |
| Tree Traversal Complete Guide | DFS, BFS, Views |
| Monotonic Stack Guide | All stack patterns |
| Must Do Questions for MAANG | Interview-focused list |
โ๏ธ Setup
git clone https://github.com/rahul22mrk/DSA-Interview-Notes-Java.git
Java 11+
โญ Star this repo if it helps your interview prep!