Pergunta de entrevista da empresa Amazon

An algorithm question on leetcode