J.P. Morgan interview question

Generic leet-code style Algorithm questions.