Pergunta de entrevista da empresa Levelset

Basic JavaScript algorithm with follow up for optimization