Google Interview Question

Complexity of the solution I provided.