Google Interview Question

2 algorisms and 1 debugging question