Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Design problems

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›Design problems

Encode and Decode Strings

advancedlayer A9 · Design problems5 tests

Design a pair of functions that send a list of strings over a channel that can only carry one string. Write encode(strs) returning a single string, and decode(str) returning the original list, so that decode(encode(list)) always equals list.

  • The strings may contain any characters at all — digits, #, brackets, spaces
  • Empty strings are valid list members, and the empty list must round-trip too
  • Any single separator character can appear inside the data, so a plain join will not do
  • Prefix each string with its length and a delimiter: 5#hello

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