eBay interview question

Graph question from Leetcode top 100