J.P. Morgan Interview Question

Two coding questions first easy and second medium?