← 返回 atlassian 的题目列表Middleware Router Wildcards and Path Params
类型:qbank
Build an in-process router that maps paths to string results. The base interface supports exact route registration and lookup; scale-ups add wildcard path segments and path parameters.
Requirements
Implement a router interface similar to:
Router {
addRoute(path: String, result: String): Unit
callRoute(path: String): String
}
Exact-match behavior:
addRoute('/bar', 'result')
callRoute('/bar') -> 'result'
Add wildcard matching, such as /a/*/c matching one segment in the middle.
Add path-parameter support after wildcard support.
Preserve deterministic matching when exact routes and wildcard routes could both match.
Notes
Trie-based segment matching is a common follow-up, especially for wildcard routes.
Another accepted direction separates exact routes from wildcard routes, checks exact matches first, then scans or matches wildcard patterns. Clarify precedence before coding.
Thread-safety may come up in coding rounds: be ready to discuss concurrent route registration and lookup.
Preparation
Implement exact match with a hash map, then migrate to a segment trie.
Test leading/trailing slashes, empty paths, multiple wildcard routes, and exact-vs-wildcard precedence.