This question evaluates a candidate's proficiency in string manipulation and serialization techniques, focusing on designing an invertible encode/decode scheme for lists of strings.
You are given a list of strings (may include digits and symbols). Implement two methods:
encode(List<String> input) -> String
: converts the list into a single encoded string.
decode(String encoded) -> List<String>
: converts the encoded string back into the original list.
Use the following encoding scheme: for each string s, append <len><s><sep> to the output, where <len> is the decimal length of s (number of characters), and <sep> is the character #.
Example:
Input: ["foo", "lis", "jljl", "12345678901"]
Lengths are 3, 3, 4, 11, so the encoded string is:
"3foo#3lis#4jljl#1112345678901#"
Implement both functions so that for any valid input list, decode(encode(input)) returns the original list.