Pregunta de entrevista de Amazon

Same as Leetcode coding problem.