Pregunta de entrevista de Anonymous

A Leetcode medium question which was from graphs.