Pergunta de entrevista da empresa Jane Street

create algorithm and it's time complexity