Tag Multi-Word Medication Mentions Using a Lexicon Trie

Last updated: November 29, 2026

Quick Overview

Given a transcript as tokens and a lexicon mapping medication phrases (one or more words) to codes, return every non-overlapping mention as (start, end, text, code), always preferring the longest phrase that matches at a position and scanning left to right.

Abridge
Coding & Algorithms
Software Engineer
Abridge
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given a transcript as tokens and a lexicon mapping medication phrases (one or more words) to codes, return every non-overlapping mention as (start, end, text, code), always preferring the longest phrase that matches at a position and scanning left to right.

Medication lists are among the highest-stakes parts of a clinical note, and Abridge must recognize phrases like insulin glargine rather than stopping at insulin. The interviewer is checking trie construction and greedy longest-match, plus awareness of clinical normalization issues.

What the Interviewer Expects
  • Build a word-level trie, not a character trie
  • Implement longest match at each start position
  • Skip past a matched phrase to avoid overlaps
  • Handle case-insensitivity
  • Analyze cost relative to the longest phrase length
Key Topics to Cover
Trie
Greedy matching
Medical NER
String processing
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 handle misspellings or ASR errors such as metforman?
  • How would you add dose and frequency extraction next to the drug name?
  • Greedy longest match can be wrong; when would you want a global optimum, and how would you get it?
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

Tokens are words; lexicon keys can be multi-word (vitamin d, insulin glargine). Matching is case-insensitive. At each position choose the longest lexicon phrase starting there; after a match, cont...

High-Level Design

Insert each phrase into a nested-dict trie keyed by lowercase word, with a $ marker holding the code at phrase ends. Scan positions left to right: walk the trie as far as tokens allow and remember t...


Submit Your Answer
Markdown supported

Related Questions