- LeetCode 21 – Merge Two Sorted Lists
The merge step of merge sort, isolated. Worth writing carefully rather than quickly, because Merge k Sorted Lists calls it and so does sorting a linked list. The part people over-engineer: splice the remaining list on in a single assignment instead of looping it out. Why the space is O(1), and why <= rather than < is the detail that shows you were thinking.
- LeetCode 20 – Valid Parentheses
The canonical 'you should have reached for a stack' problem. Nesting means the thing you must close next is the thing you opened most recently. The trick that shortens the code: push the closer you expect, not the opener, so the check becomes one equality test. Three failure modes, three checks — and why ArrayDeque beats the legacy Stack.
- LeetCode 19 – Remove Nth Node From End of List
You cannot walk a singly linked list backwards, so the nth node from the end has to be found from the front. Two pointers held a fixed distance apart do it in one pass — but the gap is n + 1, not n, because unlinking a node needs the node before it. Why the dummy head is not optional here, and an honest note on what 'one pass' actually buys.
- LeetCode 15 – 3Sum
The problem that teaches sort-then-two-pointers. The algorithm is the easy half; the half that decides whether you pass is de-duplication, and there are two separate places a duplicate gets in. Why sorting buys three things at once, why the anchor skip must compare backwards, and why no solution can beat O(n²) when the output itself can hold that many triplets.
- LeetCode 14 – Longest Common Prefix
A five-minute problem whose only real content is the edge cases. Scanning vertically — one character position down the whole array before moving right — is shorter than the horizontal version, exits at the first mismatched column, and makes the bounds check handle both short strings and empty ones in a single line. Plus the sorting trick, and why it is the worse answer.