UBS interview question

String manipulation and some bit problems.