Mastercard interview question

Graph-based problem (medium-hard) in first round