KnowledgeWala • Pillar Post • Top 50 LeetCode Series • 10 Patterns • ~12 min
This is the pillar post. Read this first — 12 minutes. Learn the 10 patterns, then go deep in 10 cluster posts, 5 problems each.
Rule: Not short, not 50 in one post. 5 problems per post, deeply explained, beautifully structured — linked as a series.
Most interviews don’t ask 50 random problems. They ask 10 patterns, with different stories. If you know the pattern, you know the solution shape before you write code.
| Pattern | What It Solves | Interview Line |
|---|---|---|
| 1. HashMap / HashSet | Lookup in O(1), duplicates, Two Sum | Trade memory for time |
| 2. Two Pointers | Sorted array, pair, palindrome | Move from both ends |
| 3. Sliding Window | Longest / smallest subarray with condition | Expand right, shrink left |
| 4. Prefix Sum / Difference | Range sum, subarray sum = K | Precompute, answer in O(1) |
| 5. Stack / Monotonic Stack | Valid parentheses, next greater | Last-in, first-out |
| 6. Binary Search | Search in sorted / rotated / answer space | Half the search each time |
| 7. DFS / BFS — Tree & Graph | Traversal, islands, shortest path | Go deep vs go level by level |
| 8. DP — 1D / 2D | Climbing stairs, knapsack, LCS | Reuse subproblem answers |
| 9. Linked List — Fast & Slow | Cycle, middle, reverse | Two pointers, different speeds |
| 10. Heap / Greedy | Top K, merge K lists, intervals | Keep best K, discard rest |
Day 1–10: One part per day, 5 problems, 40 min. Type every code, run it, say logic aloud in 60 seconds. Day 11: Re-read this pillar, try to name the pattern for each problem from memory. Interview day: When they ask a problem, first say pattern, then brute force + cost, then optimized + cost, then dry-run, then code.
| Part | Problems | Problems in Part |
|---|---|---|
| Part 1 | Problems 1–5 | 1. Two Sum EASY, 2. Contains Duplicate EASY, 3. Valid Anagram EASY, 4. Group Anagrams MEDIUM, 5. Top K Frequent Elements MEDIUM |
| Part 2 | Problems 6–10 | 6. Product of Array Except Self MEDIUM, 7. Longest Consecutive Sequence MEDIUM, 8. Best Time to Buy and Sell Stock EASY, 9. Maximum Subarray MEDIUM, 10. Valid Palindrome EASY |
| Part 3 | Problems 11–15 | 11. 3Sum MEDIUM, 12. Container With Most Water MEDIUM, 13. Longest Substring Without Repeating MEDIUM, 14. Minimum Window Substring HARD, 15. Valid Parentheses EASY |
| Part 4 | Problems 16–20 | 16. Min Stack MEDIUM, 17. Daily Temperatures MEDIUM, 18. Largest Rectangle in Histogram HARD, 19. Reverse Linked List EASY, 20. Merge Two Sorted Lists EASY |
| Part 5 | Problems 21–25 | 21. Linked List Cycle EASY, 22. Remove Nth Node From End MEDIUM, 23. Reorder List MEDIUM, 24. Add Two Numbers MEDIUM, 25. Maximum Depth of Binary Tree EASY |
| Part 6 | Problems 26–30 | 26. Same Tree EASY, 27. Invert Binary Tree EASY, 28. Binary Tree Level Order Traversal MEDIUM, 29. Lowest Common Ancestor of BST MEDIUM, 30. Validate Binary Search Tree MEDIUM |
| Part 7 | Problems 31–35 | 31. Kth Smallest Element in BST MEDIUM, 32. Diameter of Binary Tree EASY, 33. Binary Search EASY, 34. Search in Rotated Sorted Array MEDIUM, 35. Find Minimum in Rotated Sorted Array MEDIUM |
| Part 8 | Problems 36–40 | 36. Number of Islands MEDIUM, 37. Clone Graph MEDIUM, 38. Course Schedule MEDIUM, 39. Merge Intervals MEDIUM, 40. Meeting Rooms II MEDIUM |
| Part 9 | Problems 41–45 | 41. Climbing Stairs EASY, 42. House Robber MEDIUM, 43. Longest Increasing Subsequence MEDIUM, 44. Coin Change MEDIUM, 45. Longest Palindromic Substring MEDIUM |
| Part 10 | Problems 46–50 | 46. Kth Largest Element in Array MEDIUM, 47. LRU Cache MEDIUM, 48. Trapping Rain Water HARD, 49. Merge K Sorted Lists HARD, 50. Word Break MEDIUM |
Each part: 5 problems • Program → Explanation → Logic → Code → Code Explanation • Complete runnable code • ~40 min.
KnowledgeWala • LEARN TEACH GROW • knowledgewala.com