Jane Street Interview Question

create algorithm and it's time complexity