Pergunta de entrevista da empresa J.P. Morgan

Two coding questions first easy and second medium?