Company: Navi Technologies
Difficulty: medium
Minimum Spanning Tree Edge Weight Difference 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. Complete the function findMinDifference 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. findMinDifference has the following parameters: int g_nodes : the number of nodes vector<int> g_from : 1-D array, one end of each edge vector&l