UBS Interview Question

Encoding and Decoding the string