Meta interview question

Leetcode medium question on graphs