Google Interview Question

Technical: the solution, walking through it and expected runtime