Company: Mathworks_26oct
Difficulty: medium
Cool Graph Problem Description You are given an undirected connected graph of g_nodes nodes and M connections. Traverse all of the nodes at least once and store the order of traversal in array A . Then make an array B as described by the following algorithm: for (int i = 0; i Select the traversal A to create the lexicographically largest array B possible. Return the resulting array B . Examples Example 1: g_nodes = 5 g_from = [4, 5, 1, 4, 3] g_to = [5, 1, 4, 3, 2] There are g_nodes = 5 nodes and M = 5 edges. Connected pairs are elements of g_from and g_to : (4, 5), (5, 1), (1, 4), (4, 3), (3, 2) . The graph looks like this: (Image of graph with nodes 1,2,3,4,5 and edges (4,5), (5,1), (1,4), (4,3), (3,2)) Traverse the graph first and store the order of traversal in array A . Determining the order of traversal is up to you. For this example, the optimal traversal is: 5 -> 4 -> 3 -> 2 -> 3 -> 4 -> 1 A = [5, 4, 3, 2, 3, 4, 1] Array B , according to the described algorithm is: B = [5, 4, 3,