Amazon Interview Question

First question was leetcode medium involving graphs