Question d’entretien chez Jane Street

create algorithm and it's time complexity