- 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.
- MySQL – UNION and UNION ALL
Stacking result sets on top of each other instead of side by side. UNION versus UNION ALL and why the default deduplication is not free, the rules the branches have to satisfy, where ORDER BY and LIMIT go when there is more than one SELECT, MySQL 8's INTERSECT and EXCEPT, and when a UNION is the wrong tool and a conditional aggregate is the right one.
- 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).
- MySQL – Self Join
Joining a table to itself, which is not a special kind of join — it is an ordinary join where both aliases point at the same table. Why the aliases stop being optional, comparing rows within a table, finding pairs without duplicating them with `a.id < b.id`, and the classic employee-and-manager shape done on a table you can actually see.
- 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.