IBM Interview Question

coding round : greedy and graph