diff --git a/README.md b/README.md index 6bcaef1..c7faf6d 100644 --- a/README.md +++ b/README.md @@ -10,278 +10,338 @@ ## Phase I — Linear Structures (Week 1) -### 1. Hash-Based Lookup — builds on nothing -| Set | LC # | Problem | -|---|---|---| -| A | 217 | Contains Duplicate | -| A | 242 | Valid Anagram | -| A | 1 | Two Sum | -| A | 49 | Group Anagrams | -| A | 347 | Top K Frequent Elements | -| B | 383 | Ransom Note | -| B | 205 | Isomorphic Strings | -| B | 128 | Longest Consecutive Sequence | -| B | 290 | Word Pattern | - -### 2. Prefix Sum — builds on 1 -| Set | LC # | Problem | -|---|---|---| -| A | 303 | Range Sum Query | -| A | 238 | Product of Array Except Self | -| A | 560 | Subarray Sum Equals K | -| B | 525 | Contiguous Array | -| B | 974 | Subarray Sums Divisible by K | - -### 3. Two Pointers — builds on ordered iteration -| Set | LC # | Problem | -|---|---|---| -| A | 125 | Valid Palindrome | -| A | 167 | Two Sum II | -| A | 15 | 3Sum | -| A | 11 | Container With Most Water | -| A | 42 | Trapping Rain Water | -| B | 392 | Is Subsequence | -| B | 977 | Squares of a Sorted Array | -| B | 189 | Rotate Array | -| B | 80 | Remove Duplicates II | - -### 4. Sliding Window — builds on 3 -| Set | LC # | Problem | -|---|---|---| -| A | 121 | Best Time to Buy and Sell Stock | -| A | 3 | Longest Substring Without Repeating Characters | -| A | 424 | Longest Repeating Character Replacement | -| A | 567 | Permutation in String | -| A | 76 | Minimum Window Substring | -| B | 209 | Minimum Size Subarray Sum | -| B | 1004 | Max Consecutive Ones III | -| B | 643 | Maximum Average Subarray | - -### 5. Binary Search — builds on ordered/monotonic invariants -| Set | LC # | Problem | -|---|---|---| -| A | 704 | Binary Search | -| A | 74 | Search a 2D Matrix | -| A | 875 | Koko Eating Bananas | -| A | 33 | Search in Rotated Sorted Array | -| A | 153 | Find Minimum in Rotated Sorted Array | -| B | 35 | Search Insert Position | -| B | 162 | Find Peak Element | -| B | 34 | First & Last Position | -| B ⭐ | 4 | Median of Two Sorted Arrays | - -### 6. Stack — independent primitive -| Set | LC # | Problem | -|---|---|---| -| A | 20 | Valid Parentheses | -| A | 155 | Min Stack | -| A | 150 | Evaluate Reverse Polish Notation | -| B | 71 | Simplify Path | -| B ⭐ | 224 | Basic Calculator | - -### 7. Monotonic Stack — builds on 6 -| Set | LC # | Problem | -|---|---|---| -| A | 739 | Daily Temperatures | -| A | 853 | Car Fleet | -| B | 496 | Next Greater Element I | -| B | 901 | Online Stock Span | -| B ⭐ | 84 | Largest Rectangle in Histogram | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicSetLC #Problem
1. Hash-Based Lookup
builds on nothing
A217Contains Duplicate
A242Valid Anagram
A1Two Sum
A49Group Anagrams
A347Top K Frequent Elements
B383Ransom Note
B205Isomorphic Strings
B128Longest Consecutive Sequence
B290Word Pattern
2. Prefix Sum
builds on 1
A303Range Sum Query
A238Product of Array Except Self
A560Subarray Sum Equals K
B525Contiguous Array
B974Subarray Sums Divisible by K
3. Two Pointers
builds on ordered iteration
A125Valid Palindrome
A167Two Sum II
A153Sum
A11Container With Most Water
A42Trapping Rain Water
B392Is Subsequence
B977Squares of a Sorted Array
B189Rotate Array
B80Remove Duplicates II
4. Sliding Window
builds on 3
A121Best Time to Buy and Sell Stock
A3Longest Substring Without Repeating Characters
A424Longest Repeating Character Replacement
A567Permutation in String
A76Minimum Window Substring
B209Minimum Size Subarray Sum
B1004Max Consecutive Ones III
B643Maximum Average Subarray
5. Binary Search
builds on ordered / monotonic invariants
A704Binary Search
A74Search a 2D Matrix
A875Koko Eating Bananas
A33Search in Rotated Sorted Array
A153Find Minimum in Rotated Sorted Array
B35Search Insert Position
B162Find Peak Element
B34First & Last Position
B4Median of Two Sorted Arrays
6. Stack
independent primitive
A20Valid Parentheses
A155Min Stack
A150Evaluate Reverse Polish Notation
B71Simplify Path
B224Basic Calculator
7. Monotonic Stack
builds on 6
A739Daily Temperatures
A853Car Fleet
B496Next Greater Element I
B901Online Stock Span
B84Largest Rectangle in Histogram
--- -## Phase II — Nodal & Grid Structures (Week 2) - -### 8. Linked List — independent primitive -| Set | LC # | Problem | -|---|---|---| -| A | 206 | Reverse Linked List | -| A | 21 | Merge Two Sorted Lists | -| A | 141 | Linked List Cycle | -| A | 19 | Remove Nth Node From End | -| A | 143 | Reorder List | -| B | 876 | Middle of the Linked List | -| B | 92 | Reverse Linked List II | -| B | 82 | Remove Duplicates from Sorted List II | -| B | 61 | Rotate List | -| B | 86 | Partition List | - -### 9. Hybrid Structures — builds on 1 + 8 -| Set | LC # | Problem | -|---|---|---| -| A | 146 | LRU Cache | -| A | 2 | Add Two Numbers | -| B | 138 | Copy List with Random Pointer | -| B | 380 | Insert Delete GetRandom O(1) | - -### 10. Matrix Index Math — builds on 3 -| Set | LC # | Problem | -|---|---|---| -| A | 48 | Rotate Image | -| A | 54 | Spiral Matrix | -| A | 73 | Set Matrix Zeroes | -| B | 36 | Valid Sudoku | -| B | 289 | Game of Life | +## Phase II — Nodal & Grid Structures (Week 2) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicSetLC #Problem
8. Linked List
independent primitive
A206Reverse Linked List
A21Merge Two Sorted Lists
A141Linked List Cycle
A19Remove Nth Node From End
A143Reorder List
B876Middle of the Linked List
B92Reverse Linked List II
B82Remove Duplicates from Sorted List II
B61Rotate List
B86Partition List
9. Hybrid Structures
builds on 1 + 8
A146LRU Cache
A2Add Two Numbers
B138Copy List with Random Pointer
B380Insert Delete GetRandom O(1)
10. Matrix Index Math
builds on 3 — NOT graph traversal
A48Rotate Image
A54Spiral Matrix
A73Set Matrix Zeroes
B36Valid Sudoku
B289Game of Life
--- ## Phase III — Hierarchical Structures (Week 3) -### 11. Tree DFS — builds on recursion -| Set | LC # | Problem | -|---|---|---| -| A | 226 | Invert Binary Tree | -| A | 104 | Maximum Depth of Binary Tree | -| A | 100 | Same Tree | -| A | 572 | Subtree of Another Tree | -| A | 236 | Lowest Common Ancestor | -| A ⭐ | 124 | Binary Tree Maximum Path Sum | -| B | 101 | Symmetric Tree | -| B | 112 | Path Sum | -| B | 129 | Sum Root to Leaf Numbers | -| B | 543 | Diameter of Binary Tree | - -### 12. Tree BFS — builds on 6's sibling (queue) + 11 -| Set | LC # | Problem | -|---|---|---| -| A | 102 | Level Order Traversal | -| A | 199 | Right Side View | -| A | 1448 | Count Good Nodes | -| B | 103 | Zigzag Level Order | -| B | 637 | Average of Levels | - -### 13. Binary Search Tree — builds on 5 + 11 -| Set | LC # | Problem | -|---|---|---| -| A | 98 | Validate BST | -| A | 230 | Kth Smallest in BST | -| A | 235 | LCA of BST | -| A | 105 | Build from Preorder + Inorder | -| B | 530 | Minimum Absolute Difference | -| B | 173 | BST Iterator | -| B | 108 | Sorted Array to BST | - -### 14. Heap / Priority Queue — builds on trees (implicit tree over array) -| Set | LC # | Problem | -|---|---|---| -| A | 215 | Kth Largest in Array | -| A | 703 | Kth Largest in Stream | -| A | 973 | K Closest Points | -| A | 621 | Task Scheduler | -| A | 23 | Merge K Sorted Lists | -| B | 1046 | Last Stone Weight | -| B | 373 | K Pairs with Smallest Sums | -| B ⭐ | 295 | Find Median from Data Stream | -| B ⭐ | 502 | IPO | - -### 15. Trie — builds on 11 -| Set | LC # | Problem | -|---|---|---| -| A | 208 | Implement Trie | -| A | 211 | Add & Search Words | -| B | 212 | Word Search II *(needs topic 20 — schedule after)* | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicSetLC #Problem
11. Tree DFS
builds on recursion
A226Invert Binary Tree
A104Maximum Depth of Binary Tree
A100Same Tree
A572Subtree of Another Tree
A236Lowest Common Ancestor
A124Binary Tree Maximum Path Sum
B101Symmetric Tree
B112Path Sum
B129Sum Root to Leaf Numbers
B543Diameter of Binary Tree
12. Tree BFS
builds on 6's sibling (queue) + 11
A102Level Order Traversal
A199Right Side View
A1448Count Good Nodes
B103Zigzag Level Order
B637Average of Levels
13. Binary Search Tree
builds on 5 + 11
A98Validate BST
A230Kth Smallest in BST
A235LCA of BST
A105Build from Preorder + Inorder
B530Minimum Absolute Difference
B173BST Iterator
B108Sorted Array to BST
14. Heap / Priority Queue
implicit tree over array
A215Kth Largest in Array
A703Kth Largest in Stream
A973K Closest Points
A621Task Scheduler
A23Merge K Sorted Lists
B1046Last Stone Weight
B373K Pairs with Smallest Sums
B295Find Median from Data Stream
B502IPO
15. Trie
builds on 11
A208Implement Trie
A211Add & Search Words
B212Word Search II (needs topic 20 — schedule after)
--- ## Phase IV — Relational Structures (Week 4) -### 16. Graph DFS — builds on 11 + visited set -| Set | LC # | Problem | -|---|---|---| -| A | 200 | Number of Islands | -| A | 695 | Max Area of Island | -| A | 133 | Clone Graph | -| A | 417 | Pacific Atlantic Water Flow | -| A | 130 | Surrounded Regions | -| B | 399 | Evaluate Division | -| B | 261 | Graph Valid Tree | - -### 17. Graph BFS — builds on 12 + visited set -| Set | LC # | Problem | -|---|---|---| -| A | 994 | Rotting Oranges | -| A | 127 | Word Ladder | -| B | 909 | Snakes and Ladders | -| B | 433 | Minimum Genetic Mutation | -| B | 286 | Walls and Gates | - -### 18. Topological Sort — builds on 16 -| Set | LC # | Problem | -|---|---|---| -| A | 207 | Course Schedule | -| A | 210 | Course Schedule II | -| B ⭐ | 269 | Alien Dictionary | -| B | 1462 | Course Schedule IV | - -### 19. Union-Find — builds on 16's problem class -| Set | LC # | Problem | -|---|---|---| -| A | 684 | Redundant Connection | -| A | 323 | Number of Connected Components | -| B | 128 | Longest Consecutive (union-find variant) | -| B | 721 | Accounts Merge | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicSetLC #Problem
16. Graph DFS
builds on 11 + visited set
A200Number of Islands
A695Max Area of Island
A133Clone Graph
A417Pacific Atlantic Water Flow
A130Surrounded Regions
B399Evaluate Division
B261Graph Valid Tree
17. Graph BFS
builds on 12 + visited set — shortest path unweighted
A994Rotting Oranges
A127Word Ladder
B909Snakes and Ladders
B433Minimum Genetic Mutation
B286Walls and Gates
18. Topological Sort
builds on 16
A207Course Schedule
A210Course Schedule II
B269Alien Dictionary
B1462Course Schedule IV
19. Union-Find
builds on 16's problem class
A684Redundant Connection
A323Number of Connected Components
B128Longest Consecutive (union-find variant)
B721Accounts Merge
--- ## Phase V — Decision-Space Exploration (Weeks 4–5) -### 20. Backtracking — builds on 16 -| Set | LC # | Problem | -|---|---|---| -| A | 78 | Subsets | -| A | 39 | Combination Sum | -| A | 46 | Permutations | -| A | 79 | Word Search | -| B | 17 | Letter Combinations | -| B | 77 | Combinations | -| B | 22 | Generate Parentheses | -| B ⭐ | 52 | N-Queens II | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicSetLC #Problem
20. Backtracking
builds on 16 — then unlock LC 212 from topic 15
A78Subsets
A39Combination Sum
A46Permutations
A79Word Search
B17Letter Combinations
B77Combinations
B22Generate Parentheses
B52N-Queens II
21. 1-D Dynamic Programming
builds on 20
A70Climbing Stairs
A746Min Cost Climbing Stairs
A198House Robber
A213House Robber II
A322Coin Change
A300Longest Increasing Subsequence
B139Word Break
B91Decode Ways
B647Palindromic Substrings
22. Multi-D / Grid DP
builds on 21
A62Unique Paths
A64Minimum Path Sum
A1143Longest Common Subsequence
B120Triangle
B63Unique Paths II
B72Edit Distance
B221Maximal Square
B97Interleaving String
23. Greedy
builds on 21 — includes Kadane's
A53Maximum Subarray
A55Jump Game
A45Jump Game II
A134Gas Station
B122Best Time to Buy and Sell Stock II
B918Maximum Sum Circular Subarray
B763Partition Labels
24. Intervals
builds on 23
A57Insert Interval
A56Merge Intervals
A435Non-Overlapping Intervals
A253Meeting Rooms II
B228Summary Ranges
B452Minimum Arrows to Burst Balloons
B252Meeting Rooms I
+ +## Dependency Spine (Mermaid) -*(Now unlock 212 Word Search II from topic 15.)* - -### 21. 1-D Dynamic Programming — builds on 20 -| Set | LC # | Problem | -|---|---|---| -| A | 70 | Climbing Stairs | -| A | 746 | Min Cost Climbing Stairs | -| A | 198 | House Robber | -| A | 213 | House Robber II | -| A | 322 | Coin Change | -| A | 300 | Longest Increasing Subsequence | -| B | 139 | Word Break | -| B | 91 | Decode Ways | -| B | 647 | Palindromic Substrings | - -### 22. Multi-D / Grid DP — builds on 21 -| Set | LC # | Problem | -|---|---|---| -| A | 62 | Unique Paths | -| A | 64 | Minimum Path Sum | -| A | 1143 | Longest Common Subsequence | -| B | 120 | Triangle | -| B | 63 | Unique Paths II | -| B ⭐ | 72 | Edit Distance | -| B | 221 | Maximal Square | -| B ⭐ | 97 | Interleaving String | - -### 23. Greedy — builds on 21 -| Set | LC # | Problem | -|---|---|---| -| A | 53 | Maximum Subarray (Kadane's) | -| A | 55 | Jump Game | -| A | 45 | Jump Game II | -| A | 134 | Gas Station | -| B | 122 | Best Time to Buy and Sell Stock II | -| B | 918 | Maximum Sum Circular Subarray | -| B | 763 | Partition Labels | - -### 24. Intervals — builds on 23 -| Set | LC # | Problem | -|---|---|---| -| A | 57 | Insert Interval | -| A | 56 | Merge Intervals | -| A | 435 | Non-Overlapping Intervals | -| A | 253 | Meeting Rooms II | -| B | 228 | Summary Ranges | -| B | 452 | Minimum Arrows to Burst Balloons | -| B | 920 | Meeting Rooms I | +```mermaid +graph LR + T1["1 Hash"] --> T2["2 Prefix Sum"] + T3["3 Two Pointers"] --> T4["4 Sliding Window"] + T4 --> T10["10 Matrix Index Math"] + T5["5 Binary Search"] --> T13["13 BST"] + T6["6 Stack"] --> T7["7 Monotonic Stack"] + T8["8 Linked List"] --> T9["9 Hybrid"] + T1 --> T9 + T11["11 Tree DFS"] --> T13 + T11 --> T14["14 Heap"] + T11 --> T15["15 Trie"] + T11 --> T16["16 Graph DFS"] + T12["12 Tree BFS"] --> T17["17 Graph BFS"] + T16 --> T18["18 Topological Sort"] + T16 --> T19["19 Union-Find"] + T18 --> T20["20 Backtracking"] + T20 --> T21["21 DP 1-D"] + T21 --> T22["22 DP Multi-D"] + T21 --> T23["23 Greedy"] + T23 --> T24["24 Intervals"] +``` diff --git a/docs/02-concepts/02-hashing.mdx b/docs/02-concepts/02-hashing.mdx index d817e1e..45716b1 100644 --- a/docs/02-concepts/02-hashing.mdx +++ b/docs/02-concepts/02-hashing.mdx @@ -1,8 +1,6 @@ --- title: 'Hashing' description: 'In algorithms, arrays and strings are very similar. They are both ordered collections of elements. The difference is that arrays are mutable, while strings are immutable.' -sidebar: - label: Hashing --- diff --git a/docs/02-concepts/03-binary-search.mdx b/docs/02-concepts/03-binary-search.mdx new file mode 100644 index 0000000..7e00cfd --- /dev/null +++ b/docs/02-concepts/03-binary-search.mdx @@ -0,0 +1,30 @@ +--- +title: 'Binary Search' +description: 'In algorithms, arrays and strings are very similar. They are both ordered collections of elements. The difference is that arrays are mutable, while strings are immutable.' +--- + + +Technically, an array can't be resized. A dynamic array, or list, can be. In the context of algorithm problems, usually when people talk about arrays, they are referring to dynamic arrays. In this entire course, we will be talking about dynamic arrays/lists, but we will just use the word "array". + +## Time Complexity + +Arrays and strings are both ordered collections of elements. The difference is that arrays are mutable, while strings are immutable. + +| Operation | Array/List | String(Immutable) | +| --------- | ---------- | ----------------- | +| Appending to end | *O(1) | O(n) | +| Popping from end | O(1) | O(n) | +| Insertion, not from end | O(n) | O(n) | +| Deletion, not from end | O(n) | O(n) | +| Modifying an element | O(1) | O(n) | +| Random access | *O(1) | O(n) | +| Checking if an element exists | O(1) | O(n) | + +:::note[Clarification 1] +Appending to the end of a list is amortized O(1) time complexity. This means that the time complexity of appending to the end of a list is the same as the time complexity of appending to the end of an array. +::: + +:::note[Clarification 2] +Random access in this context means that you can access an element at any index in constant time. +::: + diff --git a/docs/03-guides/02-two-pointers.mdx b/docs/03-guides/02-two-pointers.mdx index 44c266d..5518bcb 100644 --- a/docs/03-guides/02-two-pointers.mdx +++ b/docs/03-guides/02-two-pointers.mdx @@ -12,11 +12,3 @@ This page is a scaffold. Notes, canonical problems, and template code are not wr -## Problems - - - - - - -