Count Routes Through Four Shop Types
Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The adjacency list is what this OpenAI question from October 2026 hinges on, and if you build it wrong the rest falls apart. You get a town of shops, each tagged with a type from 0 to 3, plus undirected roads. You count ordered routes across the four types. The rules list in the reported text is cut off, so the example is your best clue: 0 to 1 to 2 to 3 counts, and so does the reverse. If the live OA blanks you, StealthCoder runs invisibly as a safety net. Read the example closely before you code anything.
The problem
A town has shops.length shops. Shop i has type shops[i], where the four types are numbered from 0 through 3. The array roads contains undirected roads. Each pair [u, v] connects shops u and v. Return the number of ordered routes that satisfy all of these rules: Examples Example 1 shops = [0,1,2,3] roads = [[0,1],[1,2],[2,3]] return = 2 The valid ordered routes are 0 → 1 → 2 → 3 and 3 → 2 → 1 → 0.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build an adjacency list from roads, since the graph is undirected and you need fast neighbor lookups. The example suggests a route visits one shop of each type in order, 0,1,2,3 or reversed 3,2,1,0. That points to layered counting: for each shop, keep a count of ways to reach it as the next type in the chain, then pass counts along edges to neighbors of the next type. That's DP over a graph, with no need to enumerate paths. The pitfall is the missing rules. The text is truncated, so confirm whether shops can repeat and whether both directions count separately. Another trap is double counting a route in both directions when the rules treat them as distinct. Use integer-safe counts and check for modulo requirements. If you freeze on the layered transition during the live OA, StealthCoder is the hedge that reads the full prompt and gives you the code.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Count Routes Through Four Shop Types 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 would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass OpenAI's OA.
OpenAI reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Routes Through Four Shop Types FAQ
What's the core trick in this OpenAI shop routes problem?+
Build an adjacency list, then count paths layer by layer by type instead of enumerating routes. For each shop of type k, sum the counts from neighboring shops of type k-1. Do the same pass for the reversed order. This keeps it linear in shops plus roads.
Why does the example return 2 for a simple chain?+
The chain 0-1-2-3 has shop types 0,1,2,3 in order. The only valid ordered routes are walking it forward and walking it backward. Since roads are undirected, both directions are traversable, and each counts as its own ordered route.
The rules section looks cut off. What do I do?+
Work from the example and confirm the details in the live prompt. Check whether types must appear in strict order, whether either direction is allowed, and whether shops can repeat. Don't assume. Those details change the DP transition, so read the full statement before coding.
Is this graph or DP, and which should I code first?+
It's both. The graph is just the structure, while the counting is DP across type layers. Code the adjacency list first, then process types in order, accumulating counts per shop. Handle the reverse direction by running the same logic on the reversed type sequence.
How do I prepare in 48 hours for a question like this?+
Practice graph-building and layered path counting on a couple of small cases. Hand-trace the example, then try a branching case with two shops per type. Check edge cases like missing types, isolated shops, and large counts that might overflow. That covers most of what this problem tests.