Pregunta de entrevista de J.P. Morgan

Two coding questions first easy and second medium?