Pergunta de entrevista da empresa JPMorganChase

time and space complexity of the algorithm