Wayground interview question

Some DSA problem around graph. Heaps