Handle multi-source string matching and tagging
Company: Harvey
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates skills in string matching, pattern recognition, overlap handling, text annotation, and counting occurrences across multiple source strings.
Constraints
- 1 <= len(output) <= 200000
- 1 <= len(sources) <= 5000
- 1 <= sum(len(s) for s in sources) <= 200000
- All sources[i] are non-empty; duplicates allowed
- Matching is exact and case-sensitive
- Indices in annotations are 0-based, unique per region, and sorted ascending
Hints
- Use a multi-pattern automaton (Aho-Corasick) to find all matches efficiently and count overlaps.
- Build a coverage array via a difference array to merge overlapping or touching matches into maximal regions.
- To annotate each region with source indices, sweep matches alongside regions and track active matches that overlap the region.