After a great run on a retro arcade cabinet, you get to type your name onto the high-score board one letter at a time using a single spring-loaded dial and a confirm button. Every time you start a brand-new letter slot, the very first press of the dial shows 'a' in that slot; every additional press before you confirm advances that same slot to the next letter of the alphabet, wrapping from 'z' back around to 'a'. Pressing confirm locks in whatever letter the slot currently shows -- it does not change what's on screen -- and the next dial press after a confirm always begins a fresh slot at 'a' again. Given the exact nameplate target you want typed, you always use the fewest dial presses possible for every letter (you press confirm the instant a slot shows the right letter, never pressing the dial more times than that letter needs). Reconstruct, in chronological order, every string that appears on the screen immediately after each dial press. (Confirm presses never change the screen, so they never add an entry to your list.)
A single line containing target, a non-empty string of lowercase English letters.
Line 1: an integer T, the total number of screen strings recorded.
The next T lines: the screen's exact contents after each successive dial press, one per line, in chronological order.
Example 1
Input
ab
Expected
3 a aa ab
Explanation
'a' is 1 press away from a fresh slot, showing "a". After confirming, 'b' needs 2 presses from a fresh slot: the first shows "a"+"a"="aa", the second advances the new slot to 'b', showing "ab". The full sequence is a, aa, ab.
Example 2
Input
ba
Expected
3 a b ba
Explanation
'b' is 2 presses from a fresh slot: the first shows "a", the second advances to "b". After confirming, 'a' needs just 1 press from a fresh slot, appending to the confirmed "b" to show "ba". The full sequence is a, b, ba.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →