- LeetCode 42 – Trapping Rain Water
One of the most-asked Hard problems, and it defeats people because they try to find the puddles. Do not. Ask how deep the water is above one column and the answer is one line: min(maxLeft, maxRight) − height. Why two pointers can decide with half the information, and the line ordering that silently returns a number slightly too small.
- LeetCode 41 – First Missing Positive
Hard because of its constraints, not its question — a hash set solves it instantly, and O(1) space forbids one. Everything follows from a single observation: with n elements the answer is always in [1, n + 1], so every other value is noise. Cyclic sort uses the array as its own hash table, and the nested loop really is O(n).
- LeetCode 40 – Combination Sum II
Combination Sum with two changes: each element used once, and the input may contain duplicates. The first is one character; the second is one line — and `i > start` rather than `i > 0` is the most misunderstood condition in the backtracking family. Getting it wrong does not duplicate answers, it loses them, which is far harder to notice.
- LeetCode 39 – Combination Sum
The backtracking template with one twist: candidates may be reused without limit, which changes exactly one character in the recursive call. Why recursing from i rather than i + 1 is the whole difference, how the start index makes results unique structurally instead of by filtering, and why all-positive candidates are what guarantee the recursion terminates.
- LeetCode 36 – Valid Sudoku
No algorithm at all — a bookkeeping problem. Rows, columns and all nine boxes can be checked in a single pass, and the only interesting line is the formula mapping a cell to its box: (row / 3) * 3 + col / 3. Encoding three facts per cell into one set, why valid is not the same as solvable, and the bitmask version for when you are asked to drop the hashing.