J.P. Morgan Interview Question

An algorithm