Route Gateway Requests to Path Patterns With Wildcard Segments
Last updated: November 29, 2026
Quick Overview
An API gateway registers route patterns like `/v1/trips/*/receipt` where `*` matches exactly one path segment. Given registered routes and a request path, return the matching route, preferring exact segments over wildcards at the earliest differing position, or None.
Uber
November 29, 20260
0
0 solved
An API gateway registers route patterns like `/v1/trips/*/receipt` where `*` matches exactly one path segment. Given registered routes and a request path, return the matching route, preferring exact segments over wildcards at the earliest differing position, or None.
Asked in Uber onsite rounds for backend roles, reflecting how an edge gateway routes thousands of endpoints. Interviewers check a segment-level trie, precedence rules, and backtracking when the preferred branch dead-ends.
What the Interviewer Expects
- Splits paths into segments and builds a trie over segments, not characters
- Stores the route at the terminal node
- Tries the exact child before the wildcard child at each segment
- Backtracks to the wildcard when the exact branch fails deeper down
- Discusses complexity and how many wildcards cause blow-up
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Add `**` that matches zero or more segments.
- Capture wildcard values as named parameters like `{trip_id}`.
- How would you detect two registered routes that conflict?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
add(route),match(path); both are slash-separated.*matches one non-empty segment.- On ambiguity prefer the literal segment at the first position where choices differ; return the route str...
High-Level Design
Use a trie whose edges are path segments. The terminal node of each route stores its pattern. Matching is a DFS over (node, segment index): at each step first follow the literal child for the reques...