J.P. Morgan interview question

An algorithm