Meta interview question

Medium-hard Coding question from leetcode.