Attraction Route Without Reusing Trails
Reported by candidates from WhatNot's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The WhatNot OA reported in September 2026 hands you a graph with at most 12 vertices and at most 18 trails, and that tiny edge count is the whole message. It's a trail (no repeated edges) problem, so you're searching over edge subsets, not vertex permutations. You need a route from start to end that hits every desired attraction, and it has to be the lexicographically smallest one. If you blank on how to prune, StealthCoder is the safety net running invisibly during the live OA. But the pattern is learnable tonight.
The problem
An attraction park is an undirected graph. Vertices are locations and each trail is an undirected edge that may be traversed at most once. Find a route that starts at start, ends at end, and visits every vertex in desiredAttractions at least once. Other vertices may be visited, and vertices may repeat when reached through different unused trails. Return the lexicographically smallest valid vertex sequence. Compare two routes at their first differing vertex, and prefer the shorter route when one is a prefix of the other. Return an empty array when no valid route exists. Function findAttractionRoute(n: int, trails: int[][], desiredAttractions: int[], start: int, end: int) → int[] Examples Example 1 n = 5 trails = [[0,1],[1,2],[2,4],[1,3],[3,4],[1,4]] desiredAttractions = [2,3] start = 0 end = 4 return = [0,1,2,4,1,3,4] The route uses each listed trail at most once and visits both requested attractions. It is lexicographically smaller than alternatives beginning 0,1,3. Example 2 n = 4 trails = [[0,1],[1,2],[2,3]] desiredAttractions = [1,2] start = 0 end = 3 return = [0,1,2,3] The only start-to-end route visits both desired vertices. Example 3 n = 4 trails = [[0,1],[2,3]] desiredAttractions = [2] start = 0 end = 3 return = [] The graph components are disconnected. Constraints 1 <= n <= 12. 0 <= trails.length <= 18. Each trail contains two distinct vertices in [0, n - 1]; parallel trails are allowed and are distinct edges. desiredAttractions.length <= n. start, end, and every desired attraction are valid vertices.
Reported by candidates. Source: FastPrep
Pattern and pitfall
With 18 edges, brute force over edge usage is feasible, so this is backtracking with a bitmask of used edges. Run DFS from start. At each vertex, try neighbors in increasing vertex order, mark the edge used, and recurse. Track which desired attractions have been visited, also as a bitmask. When you stand on end with all attractions covered, you have a candidate. Because you explore smallest neighbor first, the first valid complete route is smallest, except for the prefix rule: stopping at end beats continuing, so check for completion before extending. Pitfalls: parallel edges are distinct, so index them by edge id, not by neighbor. Passing through end mid-route is legal. Memoize on (vertex, usedEdgeMask, visitedMask) to prune dead states, since 12 x 2^18 x 2^12 is only worth caching on failures. StealthCoder is your hedge if the pruning logic slips live.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Attraction Route Without Reusing Trails cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass WhatNot's OA.
WhatNot reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Attraction Route Without Reusing Trails FAQ
What's the trick in the WhatNot Attraction Route problem?+
Edges are the limited resource, not vertices. With at most 18 trails, a DFS carrying a used-edge bitmask is cheap enough. Try neighbors in sorted order so the first valid answer found is lexicographically smallest. Vertices can repeat freely, only edges can't.
How do I handle the lexicographic and prefix rule?+
Explore neighbors by ascending vertex id. At each step, if you're at end and every desired attraction is covered, return immediately. That enforces the shorter-prefix preference. Otherwise continue to the smallest neighbor that leads to a valid completion.
Do parallel edges matter?+
Yes. Parallel trails are distinct edges, so each gets its own index and bit in the mask. Using one doesn't block the other. Store adjacency as (neighbor, edgeId) pairs and sort by neighbor, then by edge id.
Can I pass through the end vertex before finishing?+
Yes. Nothing says end can only appear last. If you reach end early without all attractions, keep going through unused trails and come back. Only stop when end is reached and all desired vertices are visited.
How do I prepare for this in 48 hours?+
Write one bitmask backtracking solution from scratch, like an Eulerian-style trail search with state (vertex, edgeMask, visitedMask). Test the three given examples, especially the disconnected case returning an empty array. Add failure memoization only if your plain DFS looks slow.