Company: Zscalar_16nov
Difficulty: medium
Node Distances Problem Description Consider a connected graph consisting of nodes and bidirectional edges. Each edge is 1 unit of distance long, and only one edge connects any two nodes. There is one cycle in the graph. For each node, determine its shortest distance from the cycle and return the distances in an integer array. If a node is in the cycle, its distance is 0. For example, given a graph with g_nodes = 6 and g_edges = 6, with edges defined by g_from = [1, 2, 1, 3, 1, 2] and g_to = [2, 3, 5, 4, 6]. The merged lists, g_from and g_to, are [[1, 2], [2, 3], [1, 3], [3, 5], [1, 4], [2, 6]]. The resulting graph has nodes 1, 2, and 3 forming a cycle. Nodes 4, 5, and 6 are each 1 unit distance from the cycle. The return array would be [0, 0, 0, 1, 1, 1]. Complete the function nodeDistance in the editor below. The function has to return an integer array denoting the remoteness of each node from the cycle. The function nodeDistance has the following parameter(s): - int g_nodes: the numb