Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Decode String

Medium
stackstringrecursion

Given an encoded string where k[encoded] means the bracketed content is repeated k times (nestable), return the decoded string.

Input: one line, the encoded string. Output: the decoded string.

Example 1
Input:
3[a]2[bc]
Output:
aaabcbc
Example 2
Input:
3[a2[c]]
Output:
accaccacc
Example 3
Input:
2[abc]3[cd]ef
Output:
abcabccdcdcdef

Constraints

  • 1 ≤ s.length ≤ 30
  • k is a positive integer ≤ 300; input is always valid.
  • Output length ≤ 10^5.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.