Pergunta de entrevista da empresa Two Sigma

Time and Space complexity of my solution