This question evaluates proficiency in string parsing and frequency aggregation, specifically handling mixed-length encodings, tokenization of digits and '#' markers, and parsing numeric repetition counts while respecting linear-time and constant-space constraints.
You are given an encoded string s representing a string of lowercase English letters (a–z). The encoding follows these rules:
a
to
i
are encoded as digits
1
to
9
.
a -> "1"
,
b -> "2"
, …,
i -> "9"
j
to
z
are encoded as two digits followed by
#
.
j -> "10#"
,
k -> "11#"
, …,
z -> "26#"
k >= 2
times, the repetition is encoded by appending
"(k)"
immediately after that letter’s code.
"aa" -> "1(2)"
,
"ccc" -> "3(3)"
,
"jj" -> "10#(2)"
Return an integer array counts of length 26, where counts[0] is the number of 'a' characters in the decoded string, counts[1] is the number of 'b', …, and counts[25] is the number of 'z'.
s = "1226#24#"
decodes to
"abzx"
.
s = "1(2)23(3)"
decodes to
"aabccc"
.
s = "2110#(2)"
decodes to
"bajj"
.
s = "23#(2)24#25#26#23#(3)"
decodes to
"wwxyzwww"
.
s
consisting of digits,
#
,
(
, and
)
that follows the encoding rules above.
s
is validly encoded.
(12)
).
O(|s|)
time and
O(1)
extra space (excluding the output array).