Reported September 2026
Googletrie

Route Pattern Matcher

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

Google, September 2026. The Route Pattern Matcher looks like a string parsing chore, but it really reduces to matching segment arrays against a list of templates and keeping the first hit. If you've got an OA invite, expect this shape: split on slash, compare literals, capture params. The catch is the size. With up to 10000 routes and 10000 URLs, the naive nested loop can bite. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you should walk in knowing the plan.

The problem

All strings in routes are registered in the order given. A route is a slash-separated path. A segment is either a literal string or a named parameter written as {name}. A parameter segment matches exactly one non-empty URL segment.
For each string in urls, find the first registered route that has the same number of segments and whose literal segments match exactly. If no route matches, return an empty row.
For a match, return one row containing the matched route first, followed by alternating parameter names and values in their left-to-right order: [route, name1, value1, name2, value2,...]. A literal route therefore produces a one-element row.
Return one row for every URL, in input order.

Function
matchRoutes(routes: String[], urls: String[]) → String[][]

Examples
Example 1
routes = ["/users/{id}/pictures/{pictureId}","/health"]
urls = ["/users/101/pictures/1","/health","/users/1"]
return = [["/users/{id}/pictures/{pictureId}","id","101","pictureId","1"],["/health"],[]]
The first URL matches the parameterized route and extracts two values. The second matches the literal route. The final URL has too few segments, so it has no match.
Example 2
routes = ["/files/{name}","/{kind}/{id}"]
urls = ["/files/report","/orders/7"]
return = [["/files/{name}","name","report"],["/{kind}/{id}","kind","orders","id","7"]]
The first registered matching route wins. The second URL does not match the literal files segment, so it uses the fully parameterized route.

Constraints
1 <= routes.length, urls.length <= 10000
The combined length of all route and URL strings is at most 300000.
Every route and URL starts with /, contains no empty segment, and has no trailing slash.
Each parameter occupies an entire segment, uses a unique lowercase name within its route, and is written as {name}.
Literal matching is case-sensitive.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The core is simple. Split each route and URL by slash into segments. A route matches a URL if segment counts are equal and every literal segment is identical, case-sensitive. Parameter segments like {name} accept any non-empty segment and get captured in order. First registered route wins, so you can't reorder or sort. The pitfall is cost. Checking every URL against every route is up to 10^8 pairs on paper, though the 300000 total length cap helps. The safer move is a trie keyed by segment, with a literal child map and a param child, storing the earliest route index at each terminal. Since the first match by registration order wins, track the minimum index across branches, not just the first path found. Precompute parameter names per route. If the trie logic gets tangled live, StealthCoder is the hedge that can hand you a working version while you stay calm.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Route Pattern Matcher 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Route Pattern Matcher FAQ

What's the trick in the Route Pattern Matcher?+

Treat routes as segment templates. Split by slash, compare lengths, match literals exactly, capture params in order. The real trick is respecting registration order, so the earliest matching route wins, even if a later route is more specific.

Is brute force good enough here?+

Maybe, because the combined length is capped at 300000, but 10000 routes times 10000 URLs is risky. Group routes by segment count at minimum. A trie that tracks the lowest route index is the safer answer and shows better judgment.

What edge cases should I test?+

Test a URL with fewer or more segments than any route, a literal route like /health returning a one-element row, overlapping routes where a param route is registered before a literal one, and case-sensitivity. Also confirm no match returns an empty row.

How do I handle the trie backtracking issue?+

A URL segment can match both a literal child and the param child, so you can't greedily pick one. Explore both branches and keep the smallest route index that reaches a valid terminal. Then build the output row from that route's stored parameter names.

How do I prepare for this in 48 hours?+

Write the split and match function from scratch, then the trie version with min-index tracking. Run Example 2 by hand, since it tests param versus literal priority. Practice returning String[][] with empty rows so output formatting doesn't cost you.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it