An antique telephone switchboard encodes a lowercase message as a log of peg presses, recorded as a string containing only the digits '0'-'9' and the hash character '#'. The log is read left to right and decodes one letter at a time using two possible token forms:
The log is guaranteed to represent a valid encoding of some lowercase message, meaning it can always be decoded unambiguously by scanning left to right and, at each position, checking whether a two-digit-plus-hash token is present before falling back to a single digit. Decode the log into its original lowercase message.
A single line: the log string s, 1 to 2000 characters long, consisting only of the characters '0'-'9' and '#'.
A single line: the decoded lowercase message.
s consists only of digits '0'-'9' and '#'.s is guaranteed to be a valid, unambiguous encoding of some non-empty lowercase message.Example 1
Input
10#11#12#
Expected
jkl
Explanation
The log splits into three two-digit-plus-hash tokens: "10#" -> 10 -> 'j', "11#" -> 11 -> 'k', "12#" -> 12 -> 'l'. Concatenating gives "jkl".
Example 2
Input
1326#
Expected
acz
Explanation
Scanning left to right: '1' has no '#' two positions later (position 2 is '2', not '#'), so it decodes alone as 'a'. Next '3' similarly has no '#' two positions later (position 3 is '6'), so it decodes alone as 'c'. The remaining "26#" is a valid two-digit token -> 26 -> 'z'. Concatenating gives "acz".
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 →