ASAPUtils Logo ASAPUtils
Week 1

Encode and Decode Strings

Encode and Decode Strings using a length prefix, with C++ and JavaScript solutions and a clear explanation of why every delimiter-based scheme is broken and length prefixing is not.

medium Strings Strings O(n) time · O(n) space Open on LeetCode ↗

The problem

Design an algorithm to encode a list of strings into a single string, and another to decode that string back into the original list. The strings may contain any characters.

["neet","code","love","you"] -> "4#neet4#code4#love3#you" -> ["neet","code","love","you"]

Related Problems