Locate Every Dictionary Term Occurrence Inside a Page
Last updated: November 29, 2026
Quick Overview
Given a text and a list of words, return all index pairs [i, j] such that text[i..j] is one of the words, sorted by i then j.
0
0
0 solved
Given a text and a list of words, return all index pairs [i, j] such that text[i..j] is one of the words, sorted by i then j.
A Google phone screen warm-up phrased as highlighting glossary terms on a page. It checks building a trie of words and walking from each start index, collecting every end marker passed, including overlaps.
What the Interviewer Expects
- Insert words into a trie
- Walk from each start index and record each end hit
- Return overlapping and nested matches
- Produce sorted output naturally
- Compare with repeated str.find per word
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 Aho-Corasick improve the worst case?
- How would you merge overlapping matches into highlight spans?
- How would you match case-insensitively without copying the text?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: text and words (lowercase, distinct). Output: list of [i, j] with text[i:j+1] in words, sorted ascending by i, then j....
High-Level Design
Insert all words into a trie with end markers. For each start index i, walk the trie with text[i], text[i+1], .... Every time we arrive at a node marking a word end at position j, emit [i, j]....