J.P. Morgan Interview Question

They asked 2 algorithm questions.