J.P. Morgan interview question

Basic coding questions, then your thought process on them