Pregunta de entrevista de Amazon

a medium difficulty leetcode question