Pergunta de entrevista da empresa Mastercard

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