Pergunta de entrevista da empresa Meta

It was a LeetCode medium problem