Decode and Store Strings
Problem statement
Decode every string in encoded and append its decoded value to an initially empty in-memory list, processing inputs in their given order. Return that complete stored list.
For this practice exercise, each encoded string uses a flat run-length format: a token is a positive decimal count followed by one lowercase ASCII letter. Expand the token by repeating that letter exactly count times, and concatenate the expanded tokens. For example, 3a2b decodes to aaabb.
Every input string is valid. Counts have no leading zero, and there are no brackets, nesting, separators, escape rules or error records. An empty encoded string decodes to an empty string and still occupies one position in the stored list. Duplicate inputs are retained independently.
Function
decodeAndStore(encoded: String[]) → String[]Examples
Example 1
encoded = ["3a2b","1z"]return = ["aaabb","z"]The first input contains two runs; the second contains one letter.
Example 2
encoded = ["","2a1b","2a1b"]return = ["","aab","aab"]An empty string retains its position, and duplicate inputs are stored separately.
Example 3
encoded = ["12x1y"]return = ["xxxxxxxxxxxxy"]A multi-digit count belongs to one token, followed by the next token.
Constraints
0 <= encoded.length <= 1000.- Every token has a count from
1through1000followed by one lowercase ASCII letter. - The total encoded character count is at most
100000. - The total decoded character count is at most
10000. - Every encoded string follows the stated token grammar or is empty.