Amazon Interview Question

what is the time complexity and space complexity? walk me through your solution.