FastPrepCanonical Euler Trail
Problems/Canonical Euler Trail

Canonical Euler Trail

Wells Fargo logoWells Fargo● HardINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a hard graph task asking for an Euler path. The standard definition based on edges, an undirected multigraph, a promise that a trail exists, and a fixed traversal order are our assumptions. Our version is about 62% the same as the reported question.

You are given a connected undirected multigraph with vertices numbered from 1 through n. Edge i joins edgeFrom[i] and edgeTo[i]. Parallel edges are allowed.

The graph is guaranteed to have an Euler trail: a vertex sequence that uses every edge exactly once. Return the trail produced by this canonical Hierholzer order:

  1. If exactly two vertices have odd degree, start at the smaller one. Otherwise start at the smallest vertex incident to an edge.
  2. Whenever the traversal is at a vertex, consume the unused incident edge whose other endpoint is smallest. If several such edges have the same endpoint, consume the one with the smallest input index.
  3. Use Hierholzer backtracking and reverse the completed postorder sequence.

Function

canonicalEulerTrail(n: int, edgeFrom: int[], edgeTo: int[]) → int[]

Examples

Example 1

n = 3edgeFrom = [1,2]edgeTo = [2,3]return = [1,2,3]

The only Euler trail starts at odd-degree vertex 1 and follows both edges.

Example 2

n = 3edgeFrom = [1,2,3]edgeTo = [2,3,1]return = [1,2,3,1]

All degrees are even, so traversal starts at vertex 1 and takes neighbor 2 first.

Example 3

n = 4edgeFrom = [1,1,2,3]edgeTo = [2,3,4,4]return = [1,2,4,3,1]

Vertices 1 and 4 are odd; start at 1 and consume the edge to 2 before the edge to 3.

Constraints

  • 2 <= n <= 10^5.
  • 1 <= edgeFrom.length == edgeTo.length <= 2 * 10^5.
  • Every endpoint is between 1 and n, and no edge is a self-loop.
  • The graph is connected after ignoring isolated vertices and has either zero or two odd-degree vertices.
  • Every vertex from 1 through n is incident to at least one edge.

More Wells Fargo Online Assessment questions

  • Server Upgrade PlanningOA · Seen Nov 2026
  • Student and Course EnrollmentOA · Seen Nov 2026
  • Bond Interest Summary Above 3%OA · Seen Oct 2026
  • Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
  • Event Statistics AggregatorOA · Seen Sep 2026
  • Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
  • Longest Subsequence That Is a SubstringOA · Seen Jul 2026
  • Overloaded Game Account InventoriesOA · Seen Jul 2026
  • Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
  • Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026

Similar questions at other companies

  • Disaster RecoveryHeadlands Technologies · OAHeadlands Technologies interview questions
  • Lowest Common Ancestor with a Changing RootInfosys · OAInfosys interview questions
  • Largest Consistent Visiting GroupAuxoAI · OA
  • Minimum Tree Diameter After Removing K LeavesMathWorks · OAMathWorks interview questions
  • Sum Dynamic Weighted Tree DistancesJuspay · OA
  • Minimum Service Cold StartsInMobi · OAInMobi interview questions
  • Recoverable Elements from Range-Sum MeasurementsEthos Life · OA
  • Optimal TransferVisa · OAVisa interview questions
  • Divide Tree NodesGoogle · OA · ONSITE INTERVIEWGoogle interview questions
  • Evolving Merchant Clusters and Persistent PinsStripe · OAStripe interview questions

Interview reports that mention this question

  • Wells Fargo OA: What It Tests (2026)

Wells Fargo interview experiences

  • Wells Fargo SWE Intern OA and Interview Questions: 18 Experiences
All Wells Fargo interview questionsSee Wells Fargo hiring insights
Saved
class Solution {
    public int[] canonicalEulerTrail(int n, int[] edgeFrom, int[] edgeTo) {
      // write your code here
    }
}
Checking account…