Trains the technique from
LeetCode 443String CompressionThis 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 flight recorder writes one status symbol per cell into a fixed array tape, given here as a list of single-character strings. Before the tape is shipped off the aircraft, the firmware packs it down.
Packing rewrites every maximal stretch of one repeated symbol as the symbol itself, then the size of that stretch spelled out one digit per cell. A stretch of size 1 keeps the bare symbol with no size after it. A stretch of 12 equal symbols therefore takes three cells: the symbol, then 1, then 2.
The rewrite has to land inside tape, overwriting cells the firmware has already read, and may use only a constant amount of room besides tape itself. Symbols are case-sensitive, so b and B never belong to the same stretch.
Return a two-element list [length, prefix]. length is how many cells the packed tape occupies, and prefix is the list of those first length cells of tape after packing. Whatever sits beyond length is scratch and is never read back.
Example 1
Two Ts pack to `T 2` and three Gs pack to `G 3`, filling four cells; the fifth cell is left as scratch.
Example 2
The lone Q keeps no size after it, which is why the packed tape is five cells rather than six.
Example 3
The stretch is 12 long, so its size needs two cells, one per digit.
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 pack_tape(tape: list[str]) -> list:public List<Object> packTape(char[] tape)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.