Domanda di colloquio di Meta

It was a hard question on leetcode