Meta interview question

Leetcode Hard.