PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Yahoo

Merge words by head-tail chaining

Last updated: Mar 29, 2026

Quick Overview

This question evaluates graph-theoretic reasoning and string-manipulation skills, focusing on the ability to reason about ordering constraints, edge cases like self-loops and multiple identical relationships, and traversal over relationships between items.

  • Medium
  • Yahoo
  • Coding & Algorithms
  • Data Scientist

Merge words by head-tail chaining

Company: Yahoo

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given a list of lowercase words, merge them into a single string by repeatedly chaining words where the last character of the current string equals the first character of the next word. When chaining, do not duplicate the shared character. You may reorder the words arbitrarily. If multiple chains are possible, return any valid merged string; if no chain uses all words exactly once, return 'IMPOSSIBLE'. Example: ['abc','rgn','ctr'] -> 'abctrgn' because 'abc' + 'ctr' (c=c) -> 'abctr' and 'abctr' + 'rgn' (r=r) -> 'abctrgn'. Constraints: 1 <= n <= 1e5, 1 <= len(word) <= 50. Describe an algorithm that runs in near-linear time in total input size and implement it (hint: model words as edges in a 26-node directed multigraph and find an Eulerian path if in-/out-degree conditions and connectivity hold). Discuss edge cases such as multiple edges with identical endpoints, self-loops (e.g., 'aa'), and disconnected components.

Quick Answer: This question evaluates graph-theoretic reasoning and string-manipulation skills, focusing on the ability to reason about ordering constraints, edge cases like self-loops and multiple identical relationships, and traversal over relationships between items.

Related Interview Questions

  • Solve Data Structure Challenges with Python Algorithms - Yahoo (Medium)
Yahoo logo
Yahoo
Oct 13, 2025, 9:49 PM
Data Scientist
Technical Screen
Coding & Algorithms
3
0

Given a list of lowercase words, merge them into a single string by repeatedly chaining words where the last character of the current string equals the first character of the next word. When chaining, do not duplicate the shared character. You may reorder the words arbitrarily. If multiple chains are possible, return any valid merged string; if no chain uses all words exactly once, return 'IMPOSSIBLE'. Example: ['abc','rgn','ctr'] -> 'abctrgn' because 'abc' + 'ctr' (c=c) -> 'abctr' and 'abctr' + 'rgn' (r=r) -> 'abctrgn'. Constraints: 1 <= n <= 1e5, 1 <= len(word) <= 50. Describe an algorithm that runs in near-linear time in total input size and implement it (hint: model words as edges in a 26-node directed multigraph and find an Eulerian path if in-/out-degree conditions and connectivity hold). Discuss edge cases such as multiple edges with identical endpoints, self-loops (e.g., 'aa'), and disconnected components.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Yahoo•More Data Scientist•Yahoo Data Scientist•Yahoo Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.