Problem Brief
Create Lexicographically Largest Permutation
INTERNOA
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:
int g_from[]: an array of integers representing the starting nodesint g_to[]: an array of integers representing the ending nodes
Returns
int[]: the lexicographically largest permutation array B
1Example 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].
2Example 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].
3Example 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
Limits and guarantees your solution can rely on.
🫎🫎