Company: Mathworks_31july
Difficulty: medium
Cool Graph Problem Description You're given a connected, undirected graph made of g_nodes nodes and M edges. Walk through the graph so that every node gets visited at least once, recording the sequence of visited nodes in array A . From that sequence, build a second array B using this procedure: for (int i = 0; i Choose the walk A so that the resulting array B is the lexicographically largest one achievable. Output that array B . Examples Example 1: Input: g_nodes = 5 g_from = [4, 5, 1, 4, 3] g_to = [5, 1, 4, 3, 2] Explanation: This graph has g_nodes = 5 nodes and M = 5 edges. The edges, read off g_from paired with g_to , connect: (4, 5), (5, 1), (1, 4), (4, 3), (3, 2). Picture the graph laid out with these connections. Walk the graph and record the visiting order in array A ; you choose how to walk it. One walk that achieves the best result here is: 5 -> 4 -> 3 -> 2 -> 3 -> 4 -> 1 A = [5, 4, 3, 2, 3, 4, 1] Running the described procedure on this A produces: Output: [5, 4, 3, 2, 1] Sam