Bloomberg interview question

The time complexity of the solution