Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Decode String

XPChallenge Points: 20
levelLevel: Medium

You are given a string that contains encoded segments in the form of k[...], where the substring inside the brackets must be repeated k times. The value k will always be a positive integer.
The brackets are always properly matched, and the input will not contain invalid patterns.
Your task is to process the encoding and return the fully decoded string.

Example 1:

Input: s = "4[x]"

Output: "xxxx"

Example 2:

Input: s = "2[ab3[c]]"

Output: "abcccabccc"

Example 3:

Input: s = "3[z]y2[pq]"

Output: "zzzypqpq"

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result