J.P. Morgan interview question

Two coding questions first easy and second medium?