Pregunta de entrevista de Amazon

An algorithm question on leetcode