Jane Street interview question

create algorithm and it's time complexity