Skip to content

rahul22mrk/DSA-Interview-Notes-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

45 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“š DSA Interview Notes โ€” Java

Pattern-wise DSA prep ยท Interview-focused ยท Clean Java templates ยท MAANG-ready


Problems Patterns Language Level


๐ŸŸข 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

  1. Read notes first โ€” 01_*_notes.md sections 1โ€“4 (Identify, What is it, Core rules, Framework)
  2. Attempt blind โ€” Try each problem 15โ€“20 min before looking at solution
  3. Study approach table โ€” Understand each step, not just the code
  4. Re-implement from memory โ€” Write code from scratch, then check
  5. 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!

Releases

No releases published

Packages

 
 
 

Contributors