Pregunta de entrevista de J.P. Morgan

Solve programming problem and describe approach