Match Robotics Topic Subscriptions With Wildcards Using a Trie

Last updated: November 29, 2026

Quick Overview

Store message bus topic names like /sensors/lidar/front in a trie by path level and return all topics matching a subscription pattern where + matches exactly one level and # (only as the last level) matches zero or more levels.

Applied Intuition
Coding & Algorithms
Software Engineer
Applied Intuition
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Store message bus topic names like /sensors/lidar/front in a trie by path level and return all topics matching a subscription pattern where + matches exactly one level and # (only as the last level) matches zero or more levels.

Applied Intuition's vehicle software and log tooling move data over pub/sub buses, and recording or visualization filters are expressed as topic patterns. The interviewer checks trie design by path segment and correct wildcard semantics.

What the Interviewer Expects
  • Split topics on '/' and store one trie level per segment
  • Mark terminal nodes so prefixes that are also topics are found
  • Handle '+' by branching over all children at one level
  • Handle '#' by collecting the whole subtree, including the current node
  • Validate that '#' appears only last
Key Topics to Cover
tries
wildcard matching
DFS
pub/sub
prefix search
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you invert this: given a published topic, find all matching subscriptions?
  • How would you support deleting topics and pruning empty nodes?
  • What is the worst case for '+/+/+' and how would you bound it?
  • How would you make matches stream out in sorted order without a final sort?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Topics and patterns are '/'-separated with optional leading slash. + matches one level, # matches the rest including zero levels, so /sensors/camera/# matches /sensors/camera too. Return sorte...

High-Level Design

Each trie node is a dict from segment to child, plus a sentinel key holding the full topic when a topic ends there. Matching walks the pattern: a literal follows one child, + fans out to every child...


Submit Your Answer
Markdown supported

Related Questions