Pergunta de entrevista da empresa J.P. Morgan

Solve programming problem and describe approach