Solve Data Structure Challenges with Python Algorithms
Company: Yahoo
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency in fundamental data structure manipulation and string-processing algorithms, specifically preserving insertion order during list deduplication and performing iterative overlap-based word merging.
Constraints
- 0 <= n <= 200000 where n is the number of words
- 1 <= len(words[i]) and words[i] consists only of lowercase letters 'a'..'z'
- Sum of lengths of all words <= 200000
- Only a 1-character overlap (last of current with first of next) is used
- Tie-breaker: always pick the earliest valid unused word by original index
Examples
Input:
Expected Output: abctrgn
Input:
Expected Output: abcdef
Hints
- Maintain, for each starting character, a queue of indices of words that start with that character.
- Track a pointer to the earliest unused index for the fallback case.
- When overlapping, append only word[1:] to avoid duplicating the shared character.
- Use a used[] array and lazily discard used indices from character queues.