class Codec:
    def encode(self, strs: List[str]) -> str:
        """Encodes a list of strings to a single string.
        """
        res = []
        for s in strs:
            res += f"{len(s)}#{s}"
        
        return "".join(res)
        
 
    def decode(self, s: str) -> List[str]:
        """Decodes a single string to a list of strings.
        """
        res = []
        wlen = 0
        n = len(s)
        i = 0
 
        while i < n:
            num_end = i
            while s[num_end] != '#':
                num_end += 1
 
            word_len = int(s[i:num_end])
            i = num_end + 1
            
            res.append(s[i:i + word_len])
            i = i + word_len
        
        return res
 
 
# Your Codec object will be instantiated and called as such:
# codec = Codec()
# codec.decode(codec.encode(strs))

Complexity

Time:
Space:

Notes

This approach is known as chunked-transfer encoding. This should work for extended Unicode glyphs also but only b/w Python programs as strings are by default UTF-8 encoded. If another lang like JS comes into play which uses UTF-16, probably have to do additional handling.

TODO: Figure out if there’s a simple means to do cross lang string encoding (that doesn’t sound like it exists) or what are the considerations we need.