Meta interview question

Leetcode 349 and 124