Company: StoneX_22july
Difficulty: medium
Minimum Difference Spanning Tree Problem Description There is a given weighted undirected graph of g_nodes nodes numbered from 1 to g_nodes . There are g_edges edges where the i -th edge connects nodes g_from[i] and g_to[i] with a weight g_weight[i] . A spanning tree is defined as a graph obtained after deleting some edges from the original graph such that all nodes are connected by exactly g_nodes - 1 edges. Find a spanning tree of the graph such that the difference between the maximum and minimum weights of the tree is the minimum possible. Report this minimum possible difference as the answer or -1 if no spanning tree exists in the graph. Function Description Complete the function getMinDifference in the editor below. The function must return a minimum difference between the maximal and the minimal edge weight or -1 if no Spanning Tree exists. getMinDifference has the following parameters: int g_nodes : the number of nodes int edges_from[g_edges - 1] : one end of each edge int edges