UBS interview question

Encoding and Decoding the string