Domanda di colloquio di Meta

It was leetcode based question. A slight modification