cheetcode

8. Encode and Decode StringsMedium

Design a reversible encoding for a list of arbitrary strings.

Design two functions: encode turns a list of strings into one string, and decode reconstructs the exact original list.

The strings may contain separators, digits, empty strings, or any other characters, so a simple join character is not safe by itself.

Your encoding must include enough boundary information for decode to split the combined string without guessing.

Examples

Input: strs = ["lint","code","love","you"]
Output: ["lint","code","love","you"]
Input: strs = ["we","say",":","yes"]
Output: ["we","say",":","yes"]

Constraints

  • 0 <= strs.length <= 200
  • 0 <= strs[i].length <= 200
  • strs[i] may contain any valid UTF-8 text characters.