Search topics...
All Problems

Decode String

Solution Approach
Was this helpful?
MediumstringExpected: O(maxK × n) time, O(m + n) space
stack

Problem

Given an encoded string in the format k[encoded_string], return the decoded string repeated k times.

Example 1:

Input: s = "3[a]2[bc]"
Output: "aaabcbc"

Example 2:

Input: s = "3[a2[c]]"
Output: "accaccacc"

Example 3:

Input: s = "2[abc]3[cd]ef"
Output: "abcabccdcdcdef"
Reference solution unlocks after your first submission
Loading...