Wayground Interview Question

Some DSA problem around graph. Heaps