Company: Agoda_25july
Difficulty: medium
Cool Graph Traversal Problem Description You are given an undirected connected graph of g_nodes nodes and M connections. Traverse the graph and store the order of traversal in array A . You need to determine the order of traversal A such that when A is processed by the following algorithm, it produces the lexicographically largest possible array B . Return the resulting array B . The algorithm to construct array B from traversal array A is as follows: for (int i = 0; i This algorithm effectively adds elements from A to B only if they are not already present in B , maintaining their first appearance order. For example, consider a graph with g_nodes = 5 nodes and M = 5 edges. Connected pairs are elements of g_from and g_to : (4, 3), (2, 4), (1, 4), (1, 2), (2, 3). An optimal traversal for this graph is 4 -> 3 -> 2 -> 1 , resulting in array A = [4, 3, 2, 1] . Applying the described algorithm to this A yields B = [4, 3, 2, 1] , which is the largest lexicographically possible array B . Comp