Ctrl K

Digits and Hashes to Letters

Easy
Two friends pass notes in a simple code: every lowercase English letter is replaced by its position in the alphabet. Letters a through i are written as a single digit 1 to 9, and letters j through z as a two-digit number 10 to 26 followed by #. Given the encoded string cipher, return the original text. The string is guaranteed to be well-formed, so it decodes in exactly one way.
Example 1
cipher='315#45' → 'code'

3 → c, 15# → o, 4 → d, 5 → e, which spells "code".

Example 2
cipher='1226#' → 'abz'

There is no '#' after "12", so those are two separate letters, a and b, while "26#" is z.

Example 3
cipher='10#' → 'j'
Constraints
  • 1 ≤ len(cipher) ≤ 1000
  • cipher consists of digits and the # character
  • cipher is a valid encoding under the rules above
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
cipher='315#45'
Expected
'code'

Run checks the first 3 tests in your browser. Submit checks all 37 tests on the server, hidden ones included.