J.P. Morgan interview question

basic data structure, simple algorithm question.