Implement file word count
Company: Adobe
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates a candidate's skills in text processing, large-scale I/O, token normalization, memory-constrained computation and algorithmic trade-offs for frequency aggregation, and it falls under the Coding & Algorithms domain because it combines parsing, data structures and external processing concerns.
Read the full Adobe Software Engineer interview experience this question came from
Constraints
- 0 <= len(chunks) <= 100000
- 0 <= total number of characters across all chunks <= 10^7
- 0 <= k
- Chunks must be processed in order, and words may span chunk boundaries
Examples
Input: (['Hello, world! HELLO... world?', 'hello'], 2)
Expected Output: [('hello', 3), ('world', 2)]
Explanation: After normalization, the words are hello, world, hello, world, hello. The top 2 are hello (3) and world (2).
Input: (["Don", "'t stop belie", "vin'!", " Don't, stop."], 3)
Expected Output: [("don't", 2), ('stop', 2), ('believin', 1)]
Explanation: The parser must join words across chunk boundaries. `Don't` appears twice, `stop` appears twice, and `believin'` is normalized to `believin` because the trailing apostrophe is not internal.
Hints
- Keep a current token and any pending apostrophes between chunks so a word split across two chunks is still counted correctly.
- After building the frequency map, use a min-heap of size `k` to avoid sorting every distinct word when `k` is much smaller than the number of unique words.