J.P. Morgan Interview Question

basic data structure, simple algorithm question.