Encode and Decode Strings
MediumArrays & Hashing
Decode it first. Clues, constraints, pattern and plan before any code.Write two functions. encode turns a list of strings into one string, and decode turns that string back into the original list. Any characters may appear in the strings, including #, commas, digits and empty strings, so a simple separator will break.
decode(encode(["hello", "world"])) → ["hello", "world"]
decode(encode(["a#b", "", "3#x"])) → ["a#b", "", "3#x"]
decode(encode([])) → []You choose the encoded format, as long as decode(encode(strs)) == strs for every list.
Constraints
0 <= strs.length <= 2000 <= strs[i].length <= 200strs[i]may contain any character. Do not rely on any character being absent.