Next.js's file-based routing system must match incoming request paths like "/users/123/profile" against registered routes like "/users/*/profile". A HashMap works for exact matches, but wildcard routing requires a Trie. This is the same algorithm used by Express.js, FastAPI, and virtually every web framework's router.
You are writing the core router for a new web framework. You need to support fast path matching, including wildcard parameters (e.g., `/users/*/profile`). Implement an `add_route(path)` and `match_route(path)` using a Trie data structure.
βΆ Run Code to test against examples Β· Submit to judge all 5 test cases