File: decrypt-string-from-alphabet-to-integer-mapping/solution.py

Date: 2026-06-06

Time: 16:12

Decrypt String from Alphabet to Integer Mapping

Purpose

This file implements LeetCode problem #1309 — decoding a numeric string where digits 19 map to letters ai, and two-digit sequences 10#26# map to jz. It's a self-contained solution + test module following the repo's standard layout.

Key Components

Solution.sortItems(self, s: str) -> str — Misleadingly named (should be freqAlphabets per the LeetCode problem). Walks the string left-to-right, consuming either 3 characters (when a # follows at position i+2) or 1 character, converting each numeric token to its corresponding letter via chr(ord("a") + num - 1).

TestSolution — Eight test cases covering single digits, double digits with #, mixed sequences, boundary between 9/10, and the full a–z alphabet.

Patterns

Dependencies

Imports: Only unittest from the standard library — no external dependencies.

Imported by: The "Imported By" list in the prompt is misleading — those are unrelated test files across the repo. The actual consumer is decrypt-string-from-alphabet-to-integer-mapping/test_solution.py, which imports Solution from this module.

Flow

1. Initialize an empty result list and index i = 0.

2. At each position, check if s[i+2] exists and equals "#".

3. Convert the integer to a letter and append to result.

4. Join and return.

Invariants

Error Handling

None. Invalid inputs (non-digit characters, out-of-range numbers, malformed # placement) will either raise ValueError from int() or produce garbage output silently. This is typical for LeetCode solutions where inputs are guaranteed valid.

Notable Issue

The method is named sortItems, which is the name for LeetCode #1203 (Sort Items by Groups Respecting Dependencies). The correct LeetCode method name for problem #1309 is freqAlphabets. This won't affect functionality but makes the code confusing to navigate.

Topics to Explore

Beliefs