Pergunta de entrevista da empresa SLB

Graph-based LeetCode-style question, another follow-up with slightly higher difficulty. Be prepared to define classes/methods and run your own test cases.