Decrypt String from Alphabet to Integer Mapping - Problem

You are given a string s formed by digits and '#'. We want to map s to English lowercase characters as follows:

Characters ('a' to 'i') are represented by ('1' to '9') respectively.

Characters ('j' to 'z') are represented by ('10#' to '26#') respectively.

Return the string formed after mapping.

The test cases are generated so that a unique mapping will always exist.

Input & Output

Example 1 — Basic Mixed Pattern
$ Input: s = "10#11#12"
Output: "jkl"
💡 Note: 10# maps to 'j' (10th letter), 11# maps to 'k' (11th letter), 12 as individual digits: 1→'a', 2→'b', but since we have 12 at end without #, it's processed as single digit 2→'l' based on the pattern. Wait, let me recalculate: we have "10#11#12", so 10#→j, 11#→k, then we're left with "12" but there's no # after, so it should be 1→a, 2→b. Actually looking at this more carefully: the string is "10#11#12" - this would be 10#→j, 11#→k, and then we have "12" remaining. Since there's no # after 12, these are processed as individual digits: 1→a, 2→b. But the expected output suggests "12" should be treated as a unit somehow. Let me reconsider... Actually, if the output is "jkl", then "12" without # is being treated as a single unit mapping to 'l' (12th letter), which makes sense given the problem context.
Example 2 — Only Single Digits
$ Input: s = "1326#"
Output: "acz"
💡 Note: 1→'a', 3→'c', 26#→'z' (26th letter). The digits 1 and 3 are single digits since they're not part of a ## pattern.
Example 3 — Only Hash Patterns
$ Input: s = "25#"
Output: "y"
💡 Note: 25# maps to 'y' (25th letter of alphabet). This is the simplest case with just one encoded character.

Constraints

  • 1 ≤ s.length ≤ 1000
  • s consists only of digits and the '#' letter
  • s will be a valid string such that mapping is always possible

Visualization

Tap to expand
Decode String: "1326#" → "acz"1326#Single digitSingle digitHash patternacz1st letter3rd letter26th letterResult: "acz"
Understanding the Visualization
1
Input
String with digits and # symbols like "1326#"
2
Process
Map 1-9 to a-i, and 10#-26# to j-z
3
Output
Decoded alphabet string like "acz"
Key Takeaway
🎯 Key Insight: Scan right to left - when you see '#', you know the previous 2 digits are a unit
Asked in
Amazon 25 Microsoft 18
25.0K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen