Meta interview question

solve 2 medium level leetcode data-structure question