Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

strs =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Encode and Decode Strings

Medium

Design an algorithm to encode a list of strings into a single string, and then decode that string back to the original list.

Implement two functions encode and decode:

  • encode(strs) takes a list of strings and returns a single encoded string.
  • decode(s) takes the encoded string and returns the original list of strings.

Your encoding/decoding scheme must be unambiguous; i.e., decode(encode(strs)) must always return the exact original list, even with punctuation, spaces, or any UTF-8 characters.

Example 1:

Input: [\"codey\",\"love\",\"you\"]
Output: [\"codey\",\"love\",\"you\"]

Example 2:

Input: [\"we\",\"say\",\":\",\"yes\"]
Output: [\"we\",\"say\",\":\",\"yes\"]

Constraints:

  • 0 <= strs.length < 100
  • 0 <= strs[i].length < 200
  • strs[i] contains only UTF-8 characters.

Encode and Decode Strings

Medium

Design an algorithm to encode a list of strings into a single string, and then decode that string back to the original list.

Implement two functions encode and decode:

  • encode(strs) takes a list of strings and returns a single encoded string.
  • decode(s) takes the encoded string and returns the original list of strings.

Your encoding/decoding scheme must be unambiguous; i.e., decode(encode(strs)) must always return the exact original list, even with punctuation, spaces, or any UTF-8 characters.

Example 1:

Input: [\"codey\",\"love\",\"you\"]
Output: [\"codey\",\"love\",\"you\"]

Example 2:

Input: [\"we\",\"say\",\":\",\"yes\"]
Output: [\"we\",\"say\",\":\",\"yes\"]

Constraints:

  • 0 <= strs.length < 100
  • 0 <= strs[i].length < 200
  • strs[i] contains only UTF-8 characters.