Pergunta de entrevista da empresa Google

Leetcode hard question on their platform