
Count and Say
The Count and Say solution is a repeated state transition: start with "1", scan the current string into maximal consecutive runs, and emit each run as…
View solutionTrack the smallest evolving state needed to preserve a scan or simulation invariant.
Problems
Practice problems that share this primary solution pattern and compare the clues that reveal it.

The Count and Say solution is a repeated state transition: start with "1", scan the current string into maximal consecutive runs, and emit each run as…
View solution
The code is short. The contract is precise: test every legal starting position, require a complete match, and return as soon as the earliest one succeeds.
View solution
The trap is to compare whole strings before identifying the stopping condition. The answer ends at the first column where agreement breaks—or when the…
View solution
The difficult part is not recognizing a palindrome. It is preserving contiguity while avoiding repeated work.
View solution
The reliable way to solve Next Permutation is to stop thinking in four memorized steps. Read the suffix, identify where it is already maximal, then make…
View solution
A full reverse is easy to write. The interview-level move is to stop reversing when the two halves meet.
View solution
Reversing digits is easy. Reversing them without ever creating an unsafe intermediate value is the interview problem.
View solution
Adding every Roman symbol works for LVIII, but it turns IV into 6. The reliable Roman to Integer solution is a left-to-right scan with one local question:…
View solution
A reliable atoi parser is a small state machine: skip leading spaces, read one optional sign, consume one numeric prefix, and guard every accumulator…
View solution
A visual zigzag is easy to draw and surprisingly easy to implement incorrectly. The reliable solution is smaller: track the current row, track the movement…
View solution
The lists already expose digits in the order addition needs. Scan both lists together, track one carry, and keep going until there is no digit or carry…
View solution
You receive two binary strings, a and b, and must return their sum as another binary string. The inputs contain only '0' and '1', have lengths from 1 to…
View solution
The final character may be a space, so the right edge of the string is not necessarily part of the answer. The clean Length of Last Word solution is a…
View solution
Treat the product as a fixed array of decimal positions. Every digit pair has a predictable destination; carry normalization keeps those positions valid.
View solution
Do not generate the permutations. Locate the block, choose its digit, and repeat.
View solution
Adding one looks trivial until the last digit is 9. Then the problem becomes a compact state-tracking exercise: start where arithmetic begins, propagate a…
View solution
A line can contain the correct words and still be wrong: one space in the wrong gap, one missing trailing space, or full justification applied to the final…
View solution
A decimal point and an exponent are easy to track. The hard part is proving that every numeric component actually contains the digits the grammar requires.
View solution