Meta interview question

a leetcode original question in 45 min