Amazon interview question

Time complexity of the solution