Trains the technique from
LeetCode 664Strange PrinterThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A hot-foil press finishes engraved name plates one span at a time.
A plate is a row of cells numbered from 0. In a single pass the operator picks one glyph and one contiguous span of cells, and the press drives that glyph into every cell of the span. A pass wipes out whatever those cells held before it, so each cell ends up showing the glyph of the last pass that covered it.
Every plate starts blank, so a cell that no pass ever covers stays blank and the plate is rejected.
Given target, the wording the finished plate must read, return the smallest number of passes that leaves the plate reading exactly target.
Example 1
Press `k` over cells 0 through 2, then press `m` over cell 1 on its own. Two passes, and the plate reads `kmk`.
Example 2
Press `w` on cell 0, `x` on cell 1, `y` on cell 2, `z` on cell 3. Four passes, and the plate reads `wxyz`.
Example 3
Press `t` over cells 0 through 4, then press `q` over cells 2 and 3. Two passes, and the plate reads `ttqqt`.
Example 4
Press `p` over cells 0 through 2, then `q` on cell 1, then `q` on cell 3. Three passes, and the plate reads `pqpq`.
Example 5
One pass of `v` over cells 0 through 3 leaves the plate reading `vvvv`.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def strange_printer(target: str) -> int:public int strangePrinter(String target)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.