J.P. Morgan Interview Question

Two different coding questions. I haven't done the second part of interview yet