Company: Zscalar_9nov
Difficulty: medium
Maximum Difference Problem Description Given a set of nodes and a set of edges between pairs of nodes, your task is to first identify the connected components in the graph. A connected component is a group of nodes that are all linked, either directly or through other nodes in the group. For each connected component, calculate the difference between its largest and smallest node values, and return the maximum of these differences. Complete the `maximumDifference` function below. The function is expected to return an INTEGER . The function accepts an unweighted integer graph as a parameter. For the unweighted graph: The number of nodes is `g_nodes`. The number of edges is `g_edges`. An edge exists between `g_from[i]` and `g_to[i]`. int maximumDifference(int g_nodes, int g_edges, int* g_from, int* g_to) { // Function implementation } Examples Example 1: Input: g_nodes = 4, g_edges = 2 g_from = [1, 2] g_to = [2, 3] Output: 2 Explanation: Suppose you're given the following array of nodes,