Amazon interview question

Leetcode Hard problem about graphs