Minimize replacements needed to separate equal neighboring letters
Company: Headlands
Role: Quantitative Researcher
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Overview: Compute the fewest character replacements needed to eliminate equal adjacent letters in each word. Handle repeated runs, run boundaries, empty words, and independent results without constructing the modified strings.
Read the full Headlands Quantitative Researcher interview experience this question came from
Constraints
- `0 <= len(words) <= 100000`. Total character count is at most 1000000.
- Each word contains only `a` through `z` and may be empty.
Examples
Input: (['aab', 'aaaa', 'ababa', ''],)
Expected Output: [1, 2, 0, 0]
Explanation: Even and odd-length runs contribute separately; an empty word contributes zero.
Input: (['baabb', 'z'],)
Expected Output: [2, 0]
Explanation: Two separate equal pairs each require a replacement.
Hints
- Within a run of identical letters, each disjoint adjacent pair must be broken.
- Different words have independent replacement counts.