Company: Zscaler__
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. Examples Example 1: Input: g_nodes = 4, g_from = [1, 2], g_to = [2, 3] Output: 2 Explanation: Suppose you're given the following array of nodes, [1, 2, 3, 4], which are connected as follows: - Node 1 connects to Node 2 - Node 2 connects to Node 3 - Node 4 is not connected to any other node. Therefore, the connected component with the largest span among these nodes is [1, 2, 3]. The difference between the maximum and minimum values in this connected component is 3 - 1 = 2. Therefore, return 2. Constraints - 1 <= g_nodes <= 10^5 - 1 <= g_edges <= min(10^5, (g_n