Pergunta de entrevista da empresa Meta

An algorithm question from Leetcode