PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Atlassian

Design a trie-based URL router with wildcards

Last updated: Jun 15, 2026

Quick Overview

Design a trie-based URL router with wildcards evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  • Medium
  • Atlassian
  • Coding & Algorithms
  • Software Engineer

Design a trie-based URL router with wildcards

Company: Atlassian

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Question Implement a URL routing matcher that supports adding route patterns and matching request paths, using a trie (prefix tree) as the core data structure. Paths are split into `/`-delimited segments. Support static segments (e.g., `/a/b/c`) and a single-segment wildcard `*` that matches exactly one segment (e.g., `/a/*/c`). Design and implement the following: 1. **APIs.** Provide `addRoute(pattern, handler)`, `removeRoute(pattern)`, and `match(path) -> (matchedHandler, matchedPattern)`. Routes must be addable and removable at runtime. 2. **Wildcard matching.** `*` matches exactly one path segment. For example, `/a/*/c` matches `/a/x/c` and `/a/y/c` but not `/a/c` or `/a/x/y/c`. 3. **Precedence rules.** Define and implement deterministic precedence when multiple registered patterns could match a path — for example, prefer a more specific (static) match over a wildcard match. 4. **Complexity.** Analyze the time and space complexity of insertion, removal, and lookup. 5. **Concurrency.** Explain strategies for making the structure thread-safe when reads and writes (route add/remove) happen concurrently. 6. **Tests.** Provide unit tests covering edge cases such as leading/trailing slashes, the root path `/`, duplicate routes, and overlapping wildcard patterns.

Quick Answer: Design a trie-based URL router with wildcards evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Solution

# Solution Alignment The prompt asks for an implementation-level answer. The safest way to present it is to define the state, maintain clear invariants, then walk through complexity and tests. ## Problem Restatement ##### Question Implement a URL routing matcher that supports adding route patterns and matching request paths, using a trie (prefix tree) as the core data structure. Paths are split into `/`-delimited segments. Support static segments (e.g., `/a/b/c`) and a single-segment wildcard `*` that matches exactly one segment (e.g., `/a/*/c`). Design and implement the following: 1. **APIs.** Provide `addRoute(pattern, handler)`, `removeRoute(pattern)`, and `match(path) -> (matchedHandler, matchedPattern)`. Routes must be addable and removable at runtime. 2. **Wildcard matching.** `*` matches exactly one path segment. For example, `/a/*/c` matches `/a/x/c` and `/a/y/c` but not `/a/c` or `/a/x/y/c`. 3.... ## Recommended Approach Choose traversal based on the required view or aggregate. DFS is natural for subtree computations and reconstruction; BFS is natural for level order or side views. Keep per-depth or per-position state when the output depends on columns, rows, or depths. ## Correctness The implementation should maintain an invariant after each loop or operation that directly matches the problem statement. At termination, that invariant implies the returned value has considered every valid candidate exactly once, or has preserved the required data-structure state after every API call. ## Complexity Most tree traversals are O(n) time and O(h) recursion stack for DFS or O(w) queue space for BFS, where h is height and w is maximum width. ## Edge Cases and Tests Empty tree, one node, skewed tree, duplicate values when reconstruction assumes uniqueness, deep recursion, and tie-breaking for same row/column nodes.

Explanation

Rubric: the candidate should (1) choose a segment-keyed trie with a dedicated wildcard edge per node (not a character trie); (2) implement addRoute/removeRoute/match cleanly, including path normalization for leading/trailing slashes and the root path; (3) get precedence right — static beats wildcard via a DFS that tries the exact branch first and BACKTRACKS to the wildcard, since a greedy exact-first walk fails on inputs like /a/x/c with patterns {/a/x/d, /a/*/c}; (4) enforce single-segment wildcard semantics (matches exactly one segment); (5) analyze complexity (O(S) add/remove, O(S) match without wildcards, with the wildcard-backtracking caveat) and prune empty nodes on removal; and (6) discuss thread safety, ideally landing on copy-on-write with an atomic root swap for lock-free reads in a read-heavy router, or at minimum a read-write lock. Strong answers also state a duplicate-route policy and write tests for the listed edge cases.

Related Interview Questions

  • Find a secret word using match feedback - Atlassian (hard)
  • Compute a moving average on a stream - Atlassian (hard)
  • Implement sliding-window rate limiter function - Atlassian (medium)
  • Implement sequential and parallel URL requests - Atlassian (medium)
  • Merge intervals and design rating APIs - Atlassian (medium)
|Home/Coding & Algorithms/Atlassian

Design a trie-based URL router with wildcards

Atlassian logo
Atlassian
Jul 31, 2025, 12:00 AM
MediumSoftware EngineerTechnical ScreenCoding & Algorithms
11
0

Design a trie-based URL router with wildcards

Implement a URL routing matcher that supports adding route patterns and matching request paths, using a trie (prefix tree) as the core data structure. Paths are split into /-delimited segments. Support static segments (e.g., /a/b/c) and a single-segment wildcard * that matches exactly one segment (e.g., /a/*/c).

Design and implement the following:

  1. APIs. Provide addRoute(pattern, handler) , removeRoute(pattern) , and match(path) -> (matchedHandler, matchedPattern) . Routes must be addable and removable at runtime.
  2. Wildcard matching. * matches exactly one path segment. For example, /a/*/c matches /a/x/c and /a/y/c but not /a/c or /a/x/y/c .
  3. Precedence rules. Define and implement deterministic precedence when multiple registered patterns could match a path — for example, prefer a more specific (static) match over a wildcard match.
  4. Complexity. Analyze the time and space complexity of insertion, removal, and lookup.
  5. Concurrency. Explain strategies for making the structure thread-safe when reads and writes (route add/remove) happen concurrently.
  6. Tests. Provide unit tests covering edge cases such as leading/trailing slashes, the root path / , duplicate routes, and overlapping wildcard patterns.

Constraints & Assumptions

  • Preserve the scope, facts, inputs, and requested outputs from the prompt above.
  • If the prompt leaves a detail unspecified, state a reasonable assumption before relying on it.
  • Keep the answer interview-ready: concise enough to present, but concrete enough to implement or evaluate.

Clarifying Questions to Ask

  • Clarify input sizes, value ranges, mutability, return format, and tie-breaking.
  • State the target time and space complexity before coding.
  • Call out edge cases such as empty inputs, duplicates, invalid values, overflow, and boundary sizes.

What a Strong Answer Covers

  • A clear algorithm with the right data structures and enough pseudocode or code-level detail to implement it.
  • A correctness argument that explains why the algorithm covers all required cases.
  • Time and space complexity, plus at least one alternative approach when relevant.
  • Focused tests for normal cases, edge cases, and failure modes.

Follow-up Questions

  • How would the approach change if the input were streaming or too large for memory?
  • What invariants would you assert in production code?
  • Which tests would catch off-by-one, duplicate, or tie-breaking bugs?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Atlassian•More Software Engineer•Atlassian Software Engineer•Atlassian Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.