← All problems

Decode String (k[encoded])

Medium stacksrecursion LeetCode ↗
Decode an encoded string with the pattern k[encoded_string], where the encoded string inside the brackets is repeated exactly k times. Nesting is allowed: '3[a2[c]]' decodes to 'accaccacc'. k is a positive integer.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n * output), Space O(n)

Common pitfalls

  • Single-digit count assumption
  • Losing outer context on nesting

Your solution

Log in to save your code and track progress.