Meta interview question

It was leetcode based question. A slight modification