Skip to content

Problems

315 problems in NeetCode order, each with its pattern and the one-line insight that unlocks it. Work them top to bottom. The order is the curriculum.

315 of 315
  1. 1

    len(set(nums)) != len(nums)

    Arrays & Hashing · hash set

    easy
  2. 2

    Counter(s) == Counter(t)

    Arrays & Hashing · frequency

    easy
  3. 3
    Two Sumblind75frequent

    store value→index; check complement before inserting

    Arrays & Hashing · hash map

    easy
  4. 4

    key = sorted string, or a 26-length count tuple for O(n·k)

    Arrays & Hashing · hash + canonical key

    medium
  5. 5

    bucket by frequency → O(n), beats the heap's O(n log k)

    Arrays & Hashing · heap / bucket

    medium
  6. 6

    length-prefix each string (4#word); delimiters alone are ambiguous

    Arrays & Hashing · serialization

    medium
  7. 7

    left pass then right pass, O(1) extra space

    Arrays & Hashing · prefix/suffix

    medium
  8. 8

    three dicts of sets; box key is (r//3, c//3)

    Arrays & Hashing · hash sets

    medium
  9. 9

    only start counting from x where x-1 isn't in the set

    Arrays & Hashing · hash set

    medium
  10. 10

    skip non-alphanumeric, compare lowercase

    Two Pointers · converging

    easy
  11. 11

    sum too small → move left up; too big → move right down

    Two Pointers · converging

    medium
  12. 12
    3Sumblind75frequent

    fix one anchor; dedup twice (anchors and after a hit)

    Two Pointers · sort + two pointers

    medium
  13. 13

    always move the shorter line — moving the taller can't help

    Two Pointers · converging greedy

    medium
  14. 14

    water at i = min(left_max, right_max) - h[i]; advance the smaller side

    Two Pointers · two pointers

    hard
  15. 15

    track the min so far; profit = price − min

    Sliding Window · running min

    easy
  16. 16

    last-seen index map; guard last[c] >= left

    Sliding Window · variable window

    medium
  17. 17

    valid iff window_len - max_freq <= k

    Sliding Window · variable window

    medium
  18. 18

    window of len(s1), compare frequency counts

    Sliding Window · fixed window

    medium
  19. 19

    formed/required counters make validity O(1)

    Sliding Window · variable window

    hard
  20. 20

    deque of indices, values decreasing; front is the max

    Sliding Window · monotonic deque

    hard
  21. 21
    Valid Parenthesesblind75frequent

    push openers; on a closer, the top must match

    Stack · stack

    easy
  22. 22

    parallel stack of running minimums

    Stack · auxiliary stack

    medium
  23. 23

    pop two, apply, push; int(a/b) truncates toward zero

    Stack · stack

    medium
  24. 24

    rule: open < n to add '(', close < open to add ')'

    Stack · backtracking

    medium
  25. 25

    decreasing stack of indices; answer is the index distance

    Stack · monotonic stack

    medium
  26. 26

    sort by position descending; a slower car ahead absorbs you

    Stack · monotonic stack

    medium
  27. 27

    increasing stack of (start_index, height), then drain

    Stack · monotonic stack

    hard
  28. 28

    inclusive bounds, lo <= hi, always exclude mid

    Binary Search · template

    easy
  29. 29

    treat as one array: row = i // cols, col = i % cols

    Binary Search · flatten

    medium
  30. 30

    monotonic: if speed k works, every speed > k works

    Binary Search · search the answer

    medium
  31. 31

    compare nums[mid] to nums[hi], never to nums[lo]

    Binary Search · modified BS

    medium
  32. 32

    one half is always sorted — find it, then test containment

    Binary Search · modified BS

    medium
  33. 33

    dict of sorted lists + bisect_right - 1

    Binary Search · BS on timestamps

    medium
  34. 34

    binary search the split point of the smaller array

    Binary Search · BS on partition

    hard
  35. 35
    Reverse Linked Listblind75frequent

    prev / curr / next, 4 lines — memorize

    Linked List · pointer reversal

    easy
  36. 36

    compare heads, advance the smaller

    Linked List · dummy head

    easy
  37. 37

    find middle → reverse second half → interleave

    Linked List · composition

    medium
  38. 38

    fast leads slow by n; dummy head handles head removal

    Linked List · gap pointers

    medium
  39. 39

    old→new map, then a second pass wiring pointers

    Linked List · hash map

    medium
  40. 40

    loop while either list or a carry remains

    Linked List · dummy + carry

    medium
  41. 41

    they meet iff a cycle exists

    Linked List · fast/slow

    easy
  42. 42

    treat values as next pointers → cycle detection

    Linked List · Floyd's

    medium
  43. 43
    LRU Cacheblind75frequent

    sentinel head/tail; nodes must store their key for eviction

    Linked List · hashmap + DLL

    medium
  44. 44

    heap of k heads, (val, i, node) — index breaks ties

    Linked List · heap

    hard
  45. 45

    count k ahead first; reverse the block; reconnect

    Linked List · pointer surgery

    hard
  46. 46

    swap children, recurse

    Trees · any traversal

    easy
  47. 47

    1 + max(left, right)

    Trees · postorder

    easy
  48. 48

    record l + r, return 1 + max(l, r)

    Trees · postorder

    easy
  49. 49

    fuse height + balance; -1 sentinel propagates failure

    Trees · postorder

    easy
  50. 50
    Same Treeblind75

    compare structure and value simultaneously

    Trees · parallel recursion

    easy
  51. 51

    at each node, run isSameTree

    Trees · nested recursion

    easy
  52. 52

    walk down while both targets are on the same side

    Trees · BST property

    medium
  53. 53

    snapshot len(q) to process exactly one level

    Trees · BFS

    medium
  54. 54

    last node of each level

    Trees · BFS

    medium
  55. 55

    pass max_so_far down

    Trees · preorder

    medium
  56. 56
    Validate BSTblind75frequent

    inherit (low, high) — local checks are wrong

    Trees · preorder bounds

    medium
  57. 57

    iterative inorder lets you stop early, O(h+k)

    Trees · inorder

    medium
  58. 58

    index map for O(1) root lookup → O(n)

    Trees · divide & conquer

    medium
  59. 59

    clamp negative branches to 0; return one side only

    Trees · postorder

    hard
  60. 60

    # for null encodes the shape

    Trees · preorder + markers

    hard
  61. 61

    children dict + is_word flag

    Tries · trie

    medium
  62. 62

    . recurses into every child

    Tries · trie + DFS

    medium
  63. 63

    one grid DFS; prune when the prefix leaves the trie

    Tries · trie + backtracking

    hard
  64. 64

    the root is the k-th largest

    Heap / Priority Queue · min-heap size k

    easy
  65. 65

    negate values for Python's min-heap

    Heap / Priority Queue · max-heap

    easy
  66. 66

    compare squared distance — no sqrt needed

    Heap / Priority Queue · heap

    medium
  67. 67

    heap O(n log k); quickselect O(n) average

    Heap / Priority Queue · heap / quickselect

    medium
  68. 68

    most frequent task first; or the closed-form gap formula

    Heap / Priority Queue · greedy + heap

    medium
  69. 69

    merge the k followed feeds by timestamp

    Heap / Priority Queue · heap merge

    medium
  70. 70

    max-heap low half, min-heap high half, rebalance ritual

    Heap / Priority Queue · two heaps

    hard
  71. 71
    Subsetsblind75

    every node is an answer; start prevents reordering

    Backtracking · backtracking

    medium
  72. 72

    backtrack(i, ...) — same index allows reuse

    Backtracking · backtracking

    medium
  73. 73

    used[] array; scan all indices since order matters

    Backtracking · backtracking

    medium
  74. 74

    sort, then if i > start and a[i]==a[i-1]: continue

    Backtracking · backtracking + dedup

    medium
  75. 75

    sort + dedup + backtrack(i+1) for single use

    Backtracking · backtracking + dedup

    medium
  76. 76

    mark the cell, recurse, unmark

    Backtracking · grid backtracking

    medium
  77. 77

    try each prefix; recurse only if it's a palindrome

    Backtracking · backtracking

    medium
  78. 78

    digit→letters map, recurse by index

    Backtracking · backtracking

    medium
  79. 79

    conflict sets on col, r-c, r+c

    Backtracking · backtracking + pruning

    hard
  80. 80
    Number of Islandsblind75frequent

    sink each island on visit; count the starts

    Graphs · flood fill

    medium
  81. 81

    DFS returns a size

    Graphs · flood fill

    medium
  82. 82

    old→new map doubles as the visited set

    Graphs · DFS + hash map

    medium
  83. 83

    seed the queue with every gate

    Graphs · multi-source BFS

    medium
  84. 84

    count levels; track remaining fresh

    Graphs · multi-source BFS

    medium
  85. 85

    flow outward from each ocean, then intersect

    Graphs · reverse BFS/DFS

    medium
  86. 86

    mark from the border, then flip the rest

    Graphs · boundary DFS

    medium
  87. 87
    Course Scheduleblind75frequent

    processed count < n → a cycle exists

    Graphs · topological sort

    medium
  88. 88

    Kahn's, return the order

    Graphs · topological sort

    medium
  89. 89

    connected and exactly n-1 edges

    Graphs · union-find / DFS

    medium
  90. 90

    count decrements on each successful union

    Graphs · union-find

    medium
  91. 91

    the edge where union returns False

    Graphs · union-find

    medium
  92. 92

    bucket by wildcard patterns (ht) to build adjacency

    Graphs · BFS on states

    hard
  93. 93

    Eulerian path; append on dead-end, reverse at the end

    Advanced Graphs · Hierholzer's

    hard
  94. 94

    heap of (distance, node)

    Advanced Graphs · Prim's MST

    medium
  95. 95

    answer is the max of all final distances

    Advanced Graphs · Dijkstra

    medium
  96. 96

    minimize the maximum edge along the path

    Advanced Graphs · Dijkstra variant

    hard
  97. 97

    derive edges from the first differing char of adjacent words

    Advanced Graphs · topological sort

    hard
  98. 98

    exactly k+1 rounds; relax from a snapshot

    Advanced Graphs · Bellman-Ford

    medium
  99. 99

    it's Fibonacci

    1-D Dynamic Programming · linear DP

    easy
  100. 100

    dp[i] = cost[i] + min(dp[i-1], dp[i-2])

    1-D Dynamic Programming · linear DP

    easy
  101. 101
    House Robberblind75frequent

    max(skip, rob + dp[i-2])

    1-D Dynamic Programming · linear DP

    medium
  102. 102

    circular → run linear on nums[:-1] and nums[1:]

    1-D Dynamic Programming · linear DP ×2

    medium
  103. 103

    2n−1 centers, O(1) space, beats the DP

    1-D Dynamic Programming · expand around center

    medium
  104. 104

    same loop, count instead of measure

    1-D Dynamic Programming · expand around center

    medium
  105. 105

    add one-digit and two-digit options; guard leading '0'

    1-D Dynamic Programming · linear DP

    medium
  106. 106
    Coin Changeblind75frequent

    dp[0]=0, minimize; unreachable stays inf

    1-D Dynamic Programming · unbounded knapsack

    medium
  107. 107

    track min and max — a negative flips them

    1-D Dynamic Programming · linear DP

    medium
  108. 108
    Word Breakblind75

    dp[i] true if some dp[j] true and s[j:i] is a word

    1-D Dynamic Programming · segmentation DP

    medium
  109. 109

    dp[i] = LIS ending at i; then bisect for O(n log n)

    1-D Dynamic Programming · LIS

    medium
  110. 110

    reachable-sum set; odd total → immediate False

    1-D Dynamic Programming · 0/1 knapsack

    medium
  111. 111

    one row rolling: dp[j] += dp[j-1]

    2-D Dynamic Programming · grid DP

    medium
  112. 112

    match → diagonal+1; else max of the two neighbors

    2-D Dynamic Programming · two-sequence

    medium
  113. 113

    three states: hold, sold, rest

    2-D Dynamic Programming · state machine

    medium
  114. 114

    coin loop outside counts combinations, not permutations

    2-D Dynamic Programming · unbounded knapsack

    medium
  115. 115

    dp[(index, running_sum)], memoized

    2-D Dynamic Programming · 0/1 knapsack

    medium
  116. 116

    dp[i][j]: can s3[:i+j] be formed from s1[:i] + s2[:j]

    2-D Dynamic Programming · two-sequence

    medium
  117. 117

    DAG by strict increase → no visited set needed

    2-D Dynamic Programming · DFS + memo

    hard
  118. 118

    match → dp[i-1][j-1] + dp[i-1][j]; else dp[i-1][j]

    2-D Dynamic Programming · two-sequence

    hard
  119. 119
    Edit Distanceblind75frequent

    three-way min: replace, delete, insert

    2-D Dynamic Programming · two-sequence

    medium
  120. 120

    think about which balloon bursts last

    2-D Dynamic Programming · interval DP

    hard
  121. 121

    → zero occurrences, or one more if chars match

    2-D Dynamic Programming · two-sequence

    hard
  122. 122
    Maximum Subarrayblind75frequent

    curr = max(x, curr + x) — restart or extend

    Greedy · Kadane's

    medium
  123. 123
    Jump Gameblind75

    fail if i > furthest_reachable

    Greedy · greedy reach

    medium
  124. 124

    BFS by level without a queue

    Greedy · greedy levels

    medium
  125. 125

    on a deficit, no station in the failed span can start

    Greedy · greedy reset

    medium
  126. 126

    the smallest remaining card must start a group

    Greedy · greedy

    medium
  127. 127

    ignore any triplet exceeding the target in any position

    Greedy · greedy filter

    medium
  128. 128

    extend to the last occurrence of every char seen

    Greedy · greedy interval

    medium
  129. 129

    track [min_open, max_open]; widens the range

    Greedy · greedy range

    medium
  130. 130

    three phases: before / absorb / after — no sort needed

    Intervals · interval merge

    medium
  131. 131
    Merge Intervalsblind75frequent

    extend the last interval when it overlaps

    Intervals · sort by start

    medium
  132. 132

    interval scheduling — earliest end leaves the most room

    Intervals · sort by end

    medium
  133. 133

    check each adjacent pair

    Intervals · sort by start

    easy
  134. 134
    Meeting Rooms IIblind75frequent

    min-heap of end times, or separate sorted start/end arrays

    Intervals · sweep / heap

    medium
  135. 135

    sort queries, push intervals as they become active

    Intervals · sort + heap

    hard
  136. 136

    reverse rows, then transpose

    Math & Geometry · matrix

    medium
  137. 137

    four shrinking bounds + two guards for single row/col

    Math & Geometry · matrix

    medium
  138. 138

    use row 0 / col 0 as markers, then fill backward

    Math & Geometry · matrix, O(1) space

    medium
  139. 139

    fast/slow, or a seen-set

    Math & Geometry · cycle detection

    easy
  140. 140

    propagate the carry from the right

    Math & Geometry · array math

    easy
  141. 141

    square the base, halve the exponent

    Math & Geometry · binary exponentiation

    medium
  142. 142

    res[i+j+1] += d1d2, then carry

    Math & Geometry · array math

    medium
  143. 143

    count points; for each diagonal partner, multiply counts

    Math & Geometry · hash counting

    medium
  144. 144

    pairs cancel to 0

    Bit Manipulation · XOR

    easy
  145. 145

    n &= n-1 clears the lowest set bit

    Bit Manipulation · bit trick

    easy
  146. 146

    dp[i] = dp[i>>1] + (i&1)

    Bit Manipulation · DP + bits

    easy
  147. 147

    shift out of one end, into the other

    Bit Manipulation · bit trick

    easy
  148. 148

    XOR indices with values, or n(n+1)/2 − sum

    Bit Manipulation · XOR / math

    easy
  149. 149

    XOR = sum without carry; (a&b)<<1 = carry; loop

    Bit Manipulation · bit arithmetic

    medium
  150. 150

    check 32-bit bounds before the final digit

    Bit Manipulation · overflow

    medium
  151. two nested anchors → O(n³)

    Very frequently asked (do all of these) 🔥 · two pointers

    medium
  152. union by shared email, group by root

    Very frequently asked (do all of these) 🔥 · union-find

    medium
  153. carry propagation from the right, as strings

    Bit Manipulation · bit arithmetic

    easy
  154. convert the tree into a graph

    Trees & Tries, extended · build parent links + BFS

    medium
  155. DLL of frequency buckets

    Design / OOP-flavored · Design / OOP-flavored

    hard
  156. resolve collisions while pushing

    Very frequently asked (do all of these) 🔥 · stack

    medium
  157. straight simulation

    Stack · stack

    easy
  158. push signed terms; handle and / immediately

    Very frequently asked (do all of these) 🔥 · stack

    medium
  159. take every upward step: sum of all positive deltas

    Arrays & Hashing · greedy

    medium
  160. dp[day][transactions][holding]

    DP, extended · state machine + k

    hard
  161. subtract the fee on sale

    DP, extended · state machine

    medium
  162. go left, pop, go right

    Very frequently asked (do all of these) 🔥 · stack

    easy
  163. do preorder as node→right→left, then reverse

    Trees · iterative stack

    easy
  164. push right before left

    Trees · iterative stack

    easy
  165. track a column index per node

    Trees & Tries, extended · BFS + column map

    medium
  166. reverse alternate levels

    Very frequently asked (do all of these) 🔥 · BFS

    medium
  167. the answer is the shared high-bit prefix of left and right

    Bit Manipulation · common prefix

    medium
  168. pair the lightest with the heaviest if they fit; else the heaviest goes alone

    Two Pointers · sort + converge

    medium
  169. independently order rows and columns, then place

    Advanced Graphs · topological sort ×2

    hard
  170. barriers, resource counting

    Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)

    medium
  171. same shape as Koko

    Very frequently asked (do all of these) 🔥 · BS on the answer

    medium
  172. two paths simultaneously, indexed by step

    DP, extended · 3-D DP

    hard
  173. amount loop outside → counts permutations (contrast with Coin Change II)

    1-D Dynamic Programming · unbounded knapsack

    medium
  174. split, pad the shorter with zeros

    Strings · parsing

    medium
  175. nums + nums; state the O(n) anyway

    Arrays & Hashing · warm-up

    easy
  176. if the quadrant is uniform it's a leaf, else recurse into four

    Trees · divide & conquer

    medium
  177. see file 02

    Very frequently asked (do all of these) 🔥 · two pointers

    hard
  178. keep a set of the last k elements; evict as you slide

    Sliding Window · window + set

    easy
  179. mid becomes the root

    Trees & Tries, extended · divide & conquer

    easy
  180. state machine over the 5 vowels

    DP, extended · linear DP

    hard
  181. transitive reachability

    Graphs, extended · Floyd-Warshall / DFS

    medium
  182. low[child] > disc[node]

    Graphs, extended · Tarjan

    hard
  183. push counts and partial strings on [

    Very frequently asked (do all of these) 🔥 · two stacks

    medium
  184. delete children first, then re-check yourself

    Trees · postorder

    medium
  185. two children → replace with the inorder successor

    Trees & Tries, extended · BST surgery

    medium
  186. two stacks or a DLL

    Design / OOP-flavored · Design / OOP-flavored

    medium
  187. fixed array with wraparound

    Design / OOP-flavored · Design / OOP-flavored

    medium
  188. trie of paths

    Design / OOP-flavored · Design / OOP-flavored

    medium
  189. same, storing (key, value) pairs

    Arrays & Hashing · design

    easy
  190. array of buckets + chaining; explain your collision strategy

    Arrays & Hashing · design

    easy
  191. evict timestamps older than 300s

    Very frequently asked (do all of these) 🔥 · deque

    medium
  192. nested dict tree

    Design / OOP-flavored · Design / OOP-flavored

    hard
  193. cache the top-3 at each trie node

    Trees & Tries, extended · trie + heap

    hard
  194. row/col/diagonal counters, O(1) per move

    Design / OOP-flavored · Design / OOP-flavored

    medium
  195. in-progress trips + route totals

    Very frequently asked (do all of these) 🔥 · two hash maps

    medium
  196. deadlock avoidance via lock ordering

    Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)

    medium
  197. simulate bans round by round, re-queueing survivors at i + n

    Greedy · two queues

    medium
  198. fill from the destination backward

    DP, extended · reverse DP

    hard
  199. counter/base62 + two maps

    Design / OOP-flavored · Design / OOP-flavored

    medium
  200. edge weight = the ratio; multiply along the path

    Graphs, extended · weighted graph DFS

    medium
  201. 1-indexed, so decrement before each divmod

    Math & Geometry · base-26

    easy
  202. dp[i] = min extra chars from i; walk the trie forward from each index

    Tries · trie + DP

    medium
  203. compare count arrays

    Very frequently asked (do all of these) 🔥 · fixed window

    medium
  204. critical = MST weight rises without it; pseudo = forcing it in keeps the weight

    Advanced Graphs · Kruskal ×3

    hard
  205. nodes that can't reach a cycle

    Graphs, extended · reverse topo / colors

    medium
  206. find the peak, then search ascending, then descending

    Binary Search · BS ×3

    hard
  207. search for the best left boundary in [0, n-k]

    Sliding Window · binary search the window

    medium
  208. move toward the higher neighbor

    Very frequently asked (do all of these) 🔥 · BS without sorting

    medium
  209. judge has indegree n−1 and outdegree 0

    Graphs · degree counting

    easy
  210. lo < hi, hi = mid

    Very frequently asked (do all of these) 🔥 · boundary BS

    easy
  211. place each value at index v-1, then scan

    Arrays & Hashing · cyclic sort

    hard
  212. build right-skewed, prev pointer

    Very frequently asked (do all of these) 🔥 · reverse postorder

    medium
  213. (position, last_jump)

    DP, extended · DP with a state set

    hard
  214. the answer exists iff a+b == b+a; length is gcd(len(a), len(b))

    Math & Geometry · gcd

    easy
  215. union each number with each of its prime factors; connected ⟺ traversable

    Advanced Graphs · union-find over prime factors

    hard
  216. normalize by the offset from the first char

    Strings · canonical key

    medium
  217. pure binary search against an API

    Binary Search · template

    easy
  218. return (rob_this, skip_this) from each node

    Trees & Tries, extended · tree DP

    medium
  219. amortized O(1) via lazy transfer

    Very frequently asked (do all of these) 🔥 · two stacks

    easy
  220. rotate after each push

    Very frequently asked (do all of these) 🔥 · one queue

    easy
  221. naive O(nm) usually accepted

    Strings · KMP or Rabin-Karp

    easy
  222. swap-with-last on removal

    Very frequently asked (do all of these) 🔥 · array + index map

    medium
  223. splice a node between each adjacent pair

    Math & Geometry · traversal + gcd

    medium
  224. descend until a null child, attach there

    Trees · BST walk

    medium
  225. dp[n] = max(i dp[n-i], i (n-i)); the math answer is "use as many 3s as possible"

    1-D Dynamic Programming · linear DP

    medium
  226. conflict → odd cycle exists

    Graphs, extended · BFS coloring

    medium
  227. 4 per land cell, minus 2 for each shared edge

    Graphs · grid scan

    easy
  228. track the furthest reachable index and a window of valid launch points

    Greedy · BFS / sliding window

    medium
  229. binary search the value, count elements ≤ mid

    Very frequently asked (do all of these) 🔥 · heap / BS on value

    medium
  230. found in both subtrees → this node is the LCA

    Trees & Tries, extended · postorder

    medium
  231. always give the largest bills first, keeping small change in reserve

    Greedy · greedy

    easy
  232. two maps + frequency buckets — the LRU follow-up

    Design / OOP-flavored · Design / OOP-flavored

    hard
  233. hashmap of last-seen timestamps

    Design / OOP-flavored · Design / OOP-flavored

    easy
  234. compare column by column

    Strings · scan

    easy
  235. binary search the length

    Strings · rolling hash + BS

    hard
  236. take the most frequent letter unless it would make three in a row, then take the second

    Heap / Priority Queue · greedy + max-heap

    medium
  237. LCS of s and s[::-1]

    Very frequently asked (do all of these) 🔥 · 2-D DP

    medium
  238. shrink while len(window) > k

    Very frequently asked (do all of these) 🔥 · sliding window

    medium
  239. two running lengths: last comparison was up, or down

    Greedy · state DP

    medium
  240. candidate + count; the majority survives cancellation

    Very frequently asked (do all of these) 🔥 · Boyer-Moore

    easy
  241. at most two elements can exceed n/3, so track two candidates

    Arrays & Hashing · Boyer-Moore ×2

    medium
  242. pre-size each island, then test each 0

    Graphs, extended · union-find

    hard
  243. 4 buckets to a fixed target; sort descending to prune hard

    Backtracking · bitmask / backtracking

    medium
  244. run Largest Rectangle on each row

    DP, extended · histogram per row

    hard
  245. dp[i][j] = 1 + min(up, left, diagonal)

    DP, extended · 2-D DP

    medium
  246. freq[x] plus group[f] = a stack of values seen f times

    Stack · stacks by frequency

    hard
  247. answer = max(normal Kadane, total − min subarray); guard the all-negative case

    Greedy · Kadane ×2

    medium
  248. index children as 2i / 2i+1

    Trees & Tries, extended · BFS + indices

    medium
  249. greedily walk the opposite bit at each level

    Trees & Tries, extended · bitwise trie

    medium
  250. one heap of free rooms by index, one of busy rooms by end time

    Intervals · two heaps

    hard
  251. fill from the end to avoid overwriting

    Very frequently asked (do all of these) 🔥 · two pointers backward

    easy
  252. walk both, append the remainder

    Two Pointers · parallel pointers

    easy
  253. keep n's bits in the positions where x has zeros

    Bit Manipulation · bit construction

    medium
  254. three predecessors per cell

    DP, extended · grid DP

    medium
  255. strip leaves until ≤ 2 nodes remain

    Graphs, extended · topological peeling

    medium
  256. accumulate in place

    DP, extended · grid DP

    medium
  257. shrink while sum >= target

    Very frequently asked (do all of these) 🔥 · sliding window

    medium
  258. swap non-zeros forward

    Very frequently asked (do all of these) 🔥 · read/write pointers

    easy
  259. deque + running sum

    Design / OOP-flavored · Design / OOP-flavored

    easy
  260. identical to N-Queens, return only the count — no board needed

    Backtracking · backtracking

    hard
  261. three rolling variables instead of two

    1-D Dynamic Programming · linear DP

    easy
  262. islands appear incrementally

    Graphs, extended · union-find

    hard
  263. track length and count arrays

    DP, extended · LIS + counts

    medium
  264. count components in an adjacency matrix

    Very frequently asked (do all of these) 🔥 · union-find

    medium
  265. two capacity dimensions

    DP, extended · 2-D knapsack

    medium
  266. pop smaller prices, accumulating their spans

    Stack · monotonic stack

    medium
  267. each combination is a node

    Graphs, extended · BFS on states

    medium
  268. maximize the product instead of minimizing a sum

    Graphs, extended · Dijkstra variant

    medium
  269. minimise the largest single step, not the sum

    Advanced Graphs · Dijkstra on max-edge

    medium
  270. coins are the square numbers

    DP, extended · unbounded knapsack

    medium
  271. use the already-linked level above

    Very frequently asked (do all of these) 🔥 · BFS / level links

    medium
  272. two semaphores ping-ponging

    Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)

    medium
  273. semaphores / events

    Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)

    easy
  274. binary search the cumulative array

    Very frequently asked (do all of these) 🔥 · prefix + bisect

    medium
  275. pre[r][c] = sum of the rectangle from origin; inclusion–exclusion for a query

    Arrays & Hashing · 2-D prefix sum

    medium
  276. find the two swapped nodes in the sorted sequence

    Trees & Tries, extended · inorder

    medium
  277. write index trails read

    Very frequently asked (do all of these) 🔥 · read/write pointers

    easy
  278. pop larger digits while budget remains

    Very frequently asked (do all of these) 🔥 · monotonic stack

    medium
  279. n % (n - lps[-1]) == 0

    Strings · KMP

    easy
  280. dummy head, walk to left-1, reverse right-left nodes by head-insertion

    Linked List · pointer surgery

    medium
  281. swap ends inward, in place

    Two Pointers · converging

    easy
  282. " ".join(s.split()[::-1])

    Strings · parsing

    medium
  283. add each value; subtract twice when a smaller numeral precedes a larger

    Math & Geometry · parsing

    easy
  284. reverse all, reverse first k, reverse rest → O(1) space

    Two Pointers · reversal trick

    medium
  285. sort widths asc, heights desc to block ties

    DP, extended · sort + LIS

    hard
  286. start top-right; move left or down

    Very frequently asked (do all of these) 🔥 · staircase

    medium
  287. duplicates break the "which half is sorted" test; shrink lo/hi when nums[lo]==nums[mid]==nums[hi] → O(n) worst case

    Binary Search · modified BS

    medium
  288. the answer is lo when the loop exits

    Binary Search · boundary template

    easy
  289. preorder + child counts

    Design / OOP-flavored · Design / OOP-flavored

    hard
  290. grid BFS

    Graphs, extended · BFS 8-directional

    medium
  291. split on /, pop on ..

    Very frequently asked (do all of these) 🔥 · stack

    medium
  292. sort by enqueue time; heap of available tasks by (duration, index); jump the clock when idle

    Heap / Priority Queue · sort + heap

    medium
  293. serialize the board as a string key

    Graphs, extended · BFS on board states

    hard
  294. per-index (snap_id, value) list + bisect

    Design / OOP-flavored · Design / OOP-flavored

    medium
  295. implement merge sort — see 11 §11.1

    Arrays & Hashing · sorting

    medium
  296. low/mid/high partition in one pass

    Very frequently asked (do all of these) 🔥 · three pointers

    medium
  297. feasibility check = greedy chunking

    Very frequently asked (do all of these) 🔥 · BS on the answer

    hard
  298. score-difference formulation over 1–3 stones

    1-D Dynamic Programming · game theory DP

    hard
  299. whitespace → sign → digits → clamp

    Strings · parsing

    medium
  300. seed {0: 1}; count running - k

    Very frequently asked (do all of these) 🔥 · prefix + hash

    medium
  301. or the O(n) math: every bit appears in exactly half the subsets

    Backtracking · subsets

    easy
  302. carry the running number down

    Trees & Tries, extended · preorder

    medium
  303. compare left.left with right.right

    Very frequently asked (do all of these) 🔥 · parallel recursion

    easy
  304. careful spacing; last line is left-justified

    Strings · simulation

    hard
  305. list(zip(matrix)) — note it handles non-square, unlike an in-place swap

    Math & Geometry · matrix

    easy
  306. fill bottom-up, in place

    DP, extended · grid DP

    medium
  307. track the closest sum seen

    Very frequently asked (do all of these) 🔥 · two pointers

    medium
  308. obstacle cell → 0 ways

    DP, extended · grid DP

    medium
  309. enumerate the states explicitly

    Strings · state machine / regex

    hard
  310. map each letter to its rank, compare adjacent words

    Graphs · ordering

    easy
  311. thread pool + a shared visited set with a lock

    Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)

    medium
  312. return all segmentations; memoise by start index or it explodes

    Backtracking · backtracking + memo

    hard
  313. two maps, both directions

    Strings · bijection

    easy
  314. mark/unmark

    Very frequently asked (do all of these) 🔥 · backtracking

    medium
  315. bounce a row pointer

    Strings · simulation

    medium