Identify the Orchestrator in a Server Connection Graph
Company: Netapp
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
## Problem
An undirected connection list describes one orchestrator server and its workers. Every connection contains the orchestrator as one endpoint; workers never connect directly to one another.
Return the orchestrator ID.
### Function Contract
Implement `findOrchestrator(connections)`, where each connection is a two-element string array. Return a string.
### Constraints & Assumptions
- `2 <= len(connections) <= 200,000`.
- Each connection joins two distinct nonempty server IDs.
- Exactly one server ID appears in every connection.
- Duplicate connection pairs do not appear.
- Connection direction is irrelevant.
### Clarifying Questions to Ask
- Are the pairs directed? No.
- Can a worker connect to another worker? No.
- Is the orchestrator guaranteed to be unique? Yes.
- Must every worker have exactly one listed connection? The guarantee that every edge touches the orchestrator is sufficient; a worker appears on only its orchestrator edge in valid input.
```hint The first pair leaves only two candidates
The orchestrator must be one endpoint of the first connection. Use a later connection to eliminate the endpoint that is absent.
```
### Example
`[["O", "A"], ["O", "B"], ["C", "O"]]` returns `"O"`.
`[["worker-1", "root"], ["worker-2", "root"]]` returns `"root"`.
### Evaluation Focus
- Treats pairs as undirected and uses the common-endpoint guarantee.
- Does not build a general graph traversal for a star-center problem.
- Runs in `O(m)` time and `O(1)` auxiliary space beyond string references.
### Extensions to Discuss
1. How would you validate the promise that workers never connect?
2. What if a small number of malformed worker-to-worker edges may be present?
3. How would directed heartbeats change the identification rule?
Overview: Identify the single orchestrator in an undirected server graph where every connection includes that orchestrator and workers never connect directly to one another.
Return the unique server ID common to every undirected connection.
Constraints
- At least two edges.
- Exactly one ID occurs in all edges.
Examples
Input: ([['O','A'],['O','B'],['C','O']],)
Expected Output: 'O'
Explanation: Mixed positions.
Input: ([['worker-1','root'],['worker-2','root']],)
Expected Output: 'root'
Explanation: Second position.
Hints
- Inspect the first two edges.