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
Coding & Algorithms
Software Engineer
Harvey
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
sweep line
intervals
heaps
lazy deletion
redaction
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 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 Problems
Sample 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...


Submit Your Answer
Markdown supported