- LeetCode 13 – Roman to Integer
The inverse of Integer to Roman, and the trick that solved that one does not transfer. Going this way, all six subtractive pairs are handled by a single comparison: if a symbol is smaller than the one after it, subtract it. No table of pairs, no lookahead bookkeeping, and you never need to recognise CM as a unit. Java and Python, plus why not to rebuild a HashMap on every call.
- LeetCode 12 – Integer to Roman
It looks like it needs a pile of special cases — four is IV, nine is IX, forty is XL. It does not. Put the six subtractive pairs into the symbol table as if they were symbols in their own right, and the problem collapses into a plain greedy loop with no branches at all. Why greedy is provably safe once the table is descending, and why String += is the wrong way to build the answer.
- LeetCode 10 – Regular Expression Matching
The first genuinely Hard problem on the list, and the difficulty is not the code. '*' is not a character — it is a modifier on the character to its left, so x* is one indivisible unit with two branches you must both try. The recursion, why it is exponential, the memo that needs Boolean rather than boolean, the bottom-up table, and the first row that is not all false.
- LeetCode 9 – Palindrome Number
Trivial with toString, which is why the follow-up — solve it without converting to a string — is the real question. Reversing only half the number cannot overflow, unlike reversing all of it. The loop that stops at the midpoint, the odd-digit case that needs reversed / 10, and the trailing-zero guard that makes 10 return false instead of true.
- LeetCode 8 – String to Integer (atoi)
Almost no algorithm — a specification-reading exercise dressed as a coding problem, asked because sloppy engineers write parsers that eat production data. The rule that catches people is that atoi clamps to INT_MIN/INT_MAX where Reverse Integer returns zero. Four ordered steps, overflow detected before it happens, and the two Python traps: str.isdigit() and unbounded integers.