Zalando interview question

medium leetcode problem related to graphs and sorting