Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Stacks & queues

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Stacks & queues

Decode String

intermediatelayer B8 · Stacks & queues5 tests

An encoded string uses the form k[content], meaning the content repeats k times. Write decodeString(s) returning the expanded text.

  • 3[a]2[bc] expands to aaabcbc
  • Brackets nest, so 3[a2[c]] expands to accaccacc
  • k may have more than one digit, and plain letters can appear outside brackets
  • The input is always well formed, and digits only ever appear as repeat counts

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen