Meta interview question

Leetcode medium difficulty question with slight modification