Pergunta de entrevista da empresa Goldman Sachs

What is the time and space complexity of your solution