Description
Solutions
Create Lexicographically Largest Permutation
🤘 INTERN

Given an undirected connected graph of g_nodes and M connections, traverse all nodes at least once, and store the order of traversal in A. Now create the lexicographically largest array B which is a permutation of A.

Function Description

Complete the function createLexicographicallyLargestPermutation in the editor.

createLexicographicallyLargestPermutation has the following parameters:

  1. int g_from[]: an array of integers representing the starting nodes
  2. int g_to[]: an array of integers representing the ending nodes

Returns

int[]: the lexicographically largest permutation array B

Example 1:

Input:  g_from = [4, 5, 1, 4, 3], g_to = [5, 1, 4, 3, 2]
Output: [5, 4, 3, 2, 1]
Explanation:
This and the following 2 explanations are not from the official, so be careful when reading them :) The order of traversal A is [5, 4, 3, 2, 3, 4, 1]. The lexicographically largest permutation B is [5, 4, 3, 2, 1].

Example 2:

Input:  g_from = [3, 3], g_to = [1, 2]
Output: [3, 2, 1]
Explanation:
The order of traversal A can be [3, 1, 3, 2] or any other traversal that visits all nodes at least once. The lexicographically largest permutation B is [3, 2, 1].

Example 3:

Input:  g_from = [1, 2, 3, 2, 1], g_to = [2, 3, 4, 4, 4]
Output: [4, 3, 2, 1]
Explanation:
The order of traversal A can be [1, 2, 3, 4, 2, 1, 4, 4] or any other traversal that visits all nodes at least once. The lexicographically largest permutation B is [4, 3, 2, 1].
Constraints:
    🫎🫎
Thumbnail 0
Testcase

Result
Case 1

input:

output: