FastPrepCreate Lexicographically Largest Permutation
Problems/Create Lexicographically Largest Permutation

Create Lexicographically Largest Permutation

Oracle logoOracle● HardINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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

createLexicographicallyLargestPermutation(g_from: int[], g_to: int[]) → int[]

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

Examples

Example 1

g_from = [4, 5, 1, 4, 3]g_to = [5, 1, 4, 3, 2]return = [5, 4, 3, 2, 1]

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

g_from = [3, 3]g_to = [1, 2]return = [3, 2, 1]

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

g_from = [1, 2, 3, 2, 1]g_to = [2, 3, 4, 4, 4]return = [4, 3, 2, 1]

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

  • 🫎🫎

More Oracle interview questions

  • Course ScheduleONSITE INTERVIEW · Seen Nov 2026
  • Shortest Subarray with Sum at Least KONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
  • Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
  • Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
  • Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
  • Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Evolving Merchant Clusters and Persistent PinsStripe · OAStripe interview questions
  • Module Rebuild CostsAirbnb · OAAirbnb interview questions
  • Priority Graph: First Arrival TimesIntuit · OAIntuit interview questions
  • Reconstruct ItineraryTripjack · ONSITE INTERVIEWTripjack interview questions
  • Top-Rated Similar MoviesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Aggregate Machine TopologyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Deterministic Depth-First Graph TraversalWaymo · PHONE SCREENWaymo interview questions
  • Traverse an Up-Down-Right Pointer StructureBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
  • Sum Dynamic Weighted Tree DistancesJuspay · OA

Oracle interview experiences

  • Oracle SWE Onsite Interview Experience: 1 Experience
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public int[] createLexicographicallyLargestPermutation(int[] g_from, int[] g_to) {
      // write your code here
    }

}
Checking account…