Implement lossless dictionary encoding and decoding | Amplitude Interview Question