Pregunta de entrevista de Levelset

Basic JavaScript algorithm with follow up for optimization