Google interview question

Complexity of the solution I provided.