Givery Interview Question

Graph question equivalent to leetcode hard