Pregunta de entrevista de Variphy

Leetcode question followed by optimization questions.