Google interview question

It was a coding exercise.