I was asked this problem in one of the interviews :
Given an undirected graph with N nodes and M edges. Each node is initially having some value A[i]. We are also given a number K.
Now in one operation we can take one of the edges and increment the value of the 2 nodes linked through that edge by K.
I have to find minimum no. of such operations to make value of all nodes in the graph equal or -1 if it is not possible.
Wasn't able to come up with any optimized approach. I was thinking to start with node having minimum value since in order to minimize the operations we should do as less operations as possible on maximum value node. But still not able to reach any correct approach.
Constraints : Not available . Please help if you have some other way to solve this problem.