Redact Overlapping Sensitive Spans Using Label Priority
Last updated: November 29, 2026
Quick Overview
Given a text and a list of detected spans (start, end, label, priority) that may overlap, produce the redacted text where each covered character is replaced by the label of the highest priority span covering it, merging adjacent pieces with the same label.
Harvey
November 29, 20260
0
0 solved
Given a text and a list of detected spans (start, end, label, priority) that may overlap, produce the redacted text where each covered character is replaced by the label of the highest priority span covering it, merging adjacent pieces with the same label.
Harvey handles privileged client documents, and several detectors (names, account numbers, generic PII) can fire on overlapping ranges. This question checks sweep line thinking with a heap and lazy deletion, careful boundary handling, and deterministic tie breaking.
What the Interviewer Expects
- Turn spans into boundary events and sweep in position order
- Keep active spans in a max heap by priority
- Use lazy deletion to drop spans that have ended
- Emit maximal segments and merge equal adjacent labels
- Explain tie breaking and clamping of out-of-range spans
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you keep the redaction reversible for authorized users?
- What if spans come from a stream of detector outputs page by page?
- How would you prefer the longest span when priorities tie?
- How do you redact consistently across a whole matter, so the same name gets the same placeholder?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Spans use half-open [start, end) character offsets and are clamped to the text. Higher priority wins; on a tie, the span earlier in the input wins. Output a list of (start, end, label) segments fo...
High-Level Design
Collect every start and end offset as a breakpoint. Between two consecutive breakpoints, the set of covering spans is constant. Sweep breakpoints in order: push spans that start here into a max heap k...