Amazon Interview Question

Time complexity of the solution