Magicsheet logo

Decrypt String from Alphabet to Integer Mapping

Easy
12.5%
Updated 8/1/2025

Asked by 3 Companies

Topics

Decrypt String from Alphabet to Integer Mapping

What is this problem about?

The Decrypt String from Alphabet to Integer Mapping interview question involves a specialized encoding for the alphabet. Letters 'a'-'i' are represented by "1"-"9", and letters 'j'-'z' are represented by "10#"- "26#". You are given an encoded string and need to return the original decrypted string. This Decrypt String from Alphabet to Integer Mapping coding problem is a test of string parsing and look-ahead logic.

Why is this asked in interviews?

Meta and Bloomberg use this "Easy" level question to check for string traversal efficiency. It requires you to look at the current character and potentially the character two positions ahead (the '#') to decide how to parse the current segment. It’s a fundamental test of conditional logic and string-to-integer conversion.

Algorithmic pattern used

This follows the String interview pattern.

  1. Iterative Traversal: Start from the beginning of the string.
  2. Look-ahead: If i + 2 is within bounds and s[i + 2] == '#':
    • Parse s[i...i+1] as a two-digit number.
    • Convert to the corresponding character ('j' to 'z').
    • Move index i forward by 3.
  3. Otherwise:
    • Parse s[i] as a single-digit number.
    • Convert to the corresponding character ('a' to 'i').
    • Move index i forward by 1.

Example explanation

Input: "10#11#2"

  1. Index 0: s[2] is '#'. Parse "10" -> 'j'.
  2. Index 3: s[5] is '#'. Parse "11" -> 'k'.
  3. Index 6: No more '#'. Parse "2" -> 'b'. Result: "jkb".

Common mistakes candidates make

  • Incorrect Offset: Forgetting that 'a' is 1, so the mapping is (char)('a' + num - 1).
  • Index Out of Bounds: Not checking if i + 2 exists before peeking at the character there.
  • Parsing order: Trying to parse from the end can also work, but the logic for '#' placement needs to be inverted.

Interview preparation tip

For parsing problems with delimiters (like '#'), always decide if it's easier to iterate forward with a "peek" or iterate backward. For this problem, both are viable, but forward peeking is more intuitive for most.

Similar Questions