Identify the Central Sort Hub From a List of Shipping Lanes
Last updated: November 29, 2026
Quick Overview
A regional network has n facilities connected in a star: one hub links to every other facility and there are no other lanes. Given the list of lanes as pairs, return the hub.
Amazon
November 29, 20260
0
0 solved
A regional network has n facilities connected in a star: one hub links to every other facility and there are no other lanes. Given the list of lanes as pairs, return the hub.
An online assessment warm-up that checks graph modeling and whether you avoid over-building. The interviewer is looking for the observation that the first two lanes are enough, while also accepting a degree count.
What the Interviewer Expects
- Recognize that the hub is the only node shared by every edge
- Solve with a degree count in O(E)
- Improve to O(1) by checking just two edges
- Validate the star assumption if the input may be malformed
- Explain the trade-off between the two approaches
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you detect that the input is not actually a star?
- How would you find the facility with the highest degree in a general graph?
- What if lanes are directed and you need a node every other node ships into?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a list of n - 1 pairs [u, v] (n >= 3) guaranteed to form a star. Output the hub label. Labels are arbitrary integers....
High-Level Design
In a star every edge contains the hub, so the hub is the common element of any two edges. Compare the first edge's endpoints with the second edge. A general fallback, useful when input may be dirty, c...