As reported: Amazon SDE1 (AUTA) loop (May 2025), round 2 — two coding questions and two Leadership Principle questions; this was the first.
A string of lowercase letters is encoded as follows:
atoiare written as"1"to"9";jtozare written as"10#"to"26#";- if a letter occurs more than once in a row, its count is appended in parentheses right after its code — for example
"24#(2)"isxx.
Given an encoded string s, return an array of 26 integers: the number of times each letter a … z occurs in the decoded string.
Example 1
s = "1226#24#(2)"
decoded: "abzxx"
Output: [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,1]
Example 2
s = "2110#(2)"
decoded: "bajj"
Output: [1,1,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Constraints: 1 ≤ s.length ≤ 10⁵; s is a valid encoding; each count in parentheses is between 2 and 10⁴.
Clarifications
- The same letter may appear in several places; all occurrences add up.
Code runner format: one line: s as a JSON string. Implement frequency(s); the harness prints the 26 counts as a JSON array.