Decompress Encoded String - aloalgo

Decompress Encoded String

Medium

You are given an encoded string s. The encoding rule is as follows: a positive integer k followed by a lowercase English character c indicates that c should be repeated k times. Your task is to decompress the entire string. The input string s will always be valid, consisting of alternating positive integer counts and single lowercase English characters (e.g., 3a2b, 10z). There will be no standalone characters without a preceding count, and no nested compression. Counts will always be positive integers.

Example 1

Input
"3a2b"
Output
"aaabb"
Explanation:

The '3a' part decompresses to 'aaa', and the '2b' part decompresses to 'bb'. Concatenating these results in 'aaabb'.

Example 2

Input
"1a3b2c"
Output
"abbbcc"
Explanation:

Each number-character pair is decompressed: '1a' to 'a', '3b' to 'bbb', and '2c' to 'cc'.

Example 3

Input
"10z"
Output
"zzzzzzzzzz"
Explanation:

The number 10 is followed by 'z', so 'z' is repeated 10 times.

Loading...
Input
"3a2b"
Output
"aaabb"

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!