Decrypt String from Alphabet to Integer Mapping - Problem
You're a cryptographer who has intercepted an encoded message! ๐ต๏ธโโ๏ธ
The message is a string s containing only digits and '#' symbols. Your mission is to decrypt it back to readable English lowercase letters using this special mapping:
- Single digits ('1' to '9') represent letters ('a' to 'i') respectively
- Two digits followed by '#' ('10#' to '26#') represent letters ('j' to 'z') respectively
Example: The encrypted string "10#11#12" decodes to "jkl" because:
10#โ 'j' (10th letter)11#โ 'k' (11th letter)12#โ 'l' (12th letter)
๐ฏ Your goal: Return the decrypted string. The input is guaranteed to have a unique valid decoding!
Input & Output
example_1.py โ Basic Mixed Encoding
$
Input:
s = "10#11#12"
โบ
Output:
"jkl"
๐ก Note:
10# maps to 'j' (10th letter), 11# maps to 'k' (11th letter), 12# maps to 'l' (12th letter). No single digits in this example.
example_2.py โ Single Digits Only
$
Input:
s = "1326#"
โบ
Output:
"acz"
๐ก Note:
1 maps to 'a' (1st letter), 3 maps to 'c' (3rd letter), 26# maps to 'z' (26th letter). Mixed single digits and one two-digit mapping.
example_3.py โ All Single Digits
$
Input:
s = "123456789"
โบ
Output:
"abcdefghi"
๐ก Note:
Each digit 1-9 maps directly to letters a-i respectively. No '#' symbols present, so all are single-digit mappings.
Constraints
- 1 โค s.length โค 1000
- s consists of digits and the '#' symbol
- s will be a valid string such that mapping is always possible
- The mapping is always unique (no ambiguous cases)
Visualization
Tap to expand
Understanding the Visualization
1
Identify the Pattern
Recognize that '#' marks the end of two-digit codes
2
Process Backwards
Start from the end and work backwards through the string
3
Decode Each Part
Convert numbers to their corresponding alphabet positions
4
Assemble Message
Build the final decoded message
Key Takeaway
๐ฏ Key Insight: By processing the string backwards, we can easily distinguish between single-digit codes (1-9) and two-digit codes (10#-26#) without any ambiguity!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code