Meta interview question

leetcode hard question