Pregunta de entrevista de Apple

Leetcode question and previous experience