Stack pattern

Decode String

Given an encoded string using the rule k[encoded] meaning the bracketed substring is repeated k times, return the fully decoded string. Encodings may be nested. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 394
  • Medium
  • 2 approaches

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

StackLeetCode 394

Medium

From the first idea to the best one

  1. 01 Brute force · expand innermost repeatedly O(n²)O(n) space
  2. 02 Optimized · one pass with a stack O(output)O(output) space
Each approach plays step by step, with its time and space.

What you will learn

  • How to read Decode String and spot the stack pattern in it
  • Brute force · expand innermost repeatedly: O(n²) time, O(n) space
  • Optimized · one pass with a stack: O(output) time, O(output) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Stack

See Decode String run, step by step

Sign in and this page opens on the animation, with all 8 Stack problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.