CoinHako interview question

Leetcode medium question related to graphs