Design Gurus Logo
Encode and Decode Strings
Go Back

Problem Statement

Given a list of strings, your task is to develop two functions: one that encodes the list of strings into a single string, and another that decodes the resulting single string back into the original list of strings. It is crucial that the decoded list is identical to the original one.

It is given that you can use any encoding technique to encode list of string into the single string.

Examples

  1. Example 1:

    • Input: ["apple", "banana"]
    • Expected Output: ["apple", "banana"]
    • Justification: When we encode the input strings ["apple", "banana"], we get a single encoded string. Decoding this encoded string should give us the original list ["apple", "banana"].
  2. Example 2:

    • Input: ["sun", "moon", "stars"]
    • Expected Output: ["sun", "moon", "stars"]
    • Justification: After encoding the input list, decoding it should bring back the original list.
  3. Example 3:

    • Input: ["Hello123", "&*^%"]
    • Expected Output: ["Hello123", "&*^%"]
    • Justification: Regardless of the content of the string (special characters, numbers, etc.), decoding the encoded list should reproduce the original list.

Constraints:

  • 1 <= strs.length <= 200
  • 0 <= strs[i].length <= 200
  • strs[i] contains any possible characters out of 256 valid ASCII characters.

Try it yourself

Try solving this question here:

Python3
Python3