Google Interview Question

It was a coding exercise.