- MySQL – Subqueries
A query inside a query. Scalar subqueries in the select list, subqueries in WHERE with IN, EXISTS and the comparison operators, derived tables in FROM and why they need an alias, correlated subqueries and why they are the expensive kind, the NOT IN trap that returns nothing at all when the inner query yields a NULL, and when to reach for a join instead.
- LeetCode 46 – Permutations
The reference implementation of backtracking, and its value is the contrast with the combination problems. There a start index stops the same set appearing in different orders; here the different orders are the answer, so start disappears and used[] takes its job. Undo both pieces of state, or you get one permutation and then nothing.
- MySQL – GROUP BY and HAVING
Collapsing many rows into one per group. COUNT, SUM, AVG, MIN and MAX, grouping by several columns, HAVING versus WHERE and why they are not interchangeable, counting with COUNT(*) versus COUNT(column) when NULLs are involved, WITH ROLLUP for subtotals, and ONLY_FULL_GROUP_BY — the mode that is ON by default in MySQL 8 and rejects the sloppy GROUP BY that MySQL 5 quietly accepted.
- LeetCode 43 – Multiply Strings
Long multiplication as you learned it at school and then forgot. It hinges on one piece of index arithmetic — the product of digits i and j lands at i + j + 1, carrying into i + j — which is worth deriving rather than memorising. Why the result needs exactly m + n slots, and why an intermediate slot going above 9 is harmless.
- 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.