Amazon Interview Question

Time complexity and correctness of the given code.