Two Sigma Interview Question

Time and Space complexity of my solution