Merge Overlapping PII Detections Before Storing a Transcript

Last updated: November 29, 2026

Quick Overview

Several PII detectors (card numbers, addresses, generic numbers) return character spans over the same transcript, often overlapping. Merge the spans, label each merged span with its highest-priority type, and return the redacted text.

Cresta
Coding & Algorithms
Software Engineer
Cresta
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


Several PII detectors (card numbers, addresses, generic numbers) return character spans over the same transcript, often overlapping. Merge the spans, label each merged span with its highest-priority type, and return the redacted text.

Contact center transcripts carry card numbers and personal data, and Cresta must redact them for PCI and privacy compliance before data is stored or used for training. The question checks interval merging with a priority rule and careful string reconstruction without off-by-one leaks of sensitive characters.

What the Interviewer Expects
  • Sort spans and merge overlaps in one pass
  • Pick the strongest label for a merged span by a priority map
  • Clamp spans to text bounds and drop empty ones
  • Rebuild the string in one pass rather than repeated slicing
  • Explain why under-redaction is worse than over-redaction
Key Topics to Cover
Interval merging
PII redaction
String building
Compliance
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
  • Should touching but non-overlapping spans merge? What would you choose for compliance?
  • How would you redact the matching audio segments using word timestamps?
  • How would you redact a card number that ASR split across two utterances?
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

Input: text, list of (start, end, label) half-open spans, and a priority list such as [CARD, ADDRESS, NUMBER]. Overlapping spans merge into one, labeled with the highest-priority label seen. Outpu...

High-Level Design

Clean spans (clamp to text, drop empty), sort by start, sweep: if a span starts before the current merged span ends, extend the end and maybe upgrade the label; otherwise start a new merged span. Then...


Submit Your Answer
Markdown supported

Related Questions