Pregunta de entrevista de Two Sigma

Time and Space complexity of my solution