Min Num Unique Distribution Hubs
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's 'Min Num Unique Distribution Hubs' hit the OA circuit in April 2025, and it's a graph optimization problem disguised as a logistics question. You're looking at a shortest-path or minimum-cost network design scenario where you need to find the smallest set of hubs that can service all locations under given distance or connectivity constraints. The trick is recognizing whether this is a Union-Find problem, a greedy edge-selection problem, or a BFS traversal. StealthCoder will catch the pattern instantly if you blank on whether to sort by distance first or build a minimum spanning tree.
Pattern and pitfall
The core challenge here is determining which hubs are actually necessary. You're likely working with a graph where each location needs to connect to at least one hub, and you want to minimize the number of hubs while keeping distances or costs under a threshold. This screams either Kruskal's algorithm (if you're building a minimum spanning tree and counting components) or a greedy approach where you sort edges by weight and union locations greedily. The pitfall: overcomplicating it by trying to optimize hub placement instead of just counting the minimum number needed to achieve full coverage. BFS or Union-Find is usually the fast path here. If the problem involves distance matrices or coordinates, you might need to precompute pairwise distances first, then apply the graph logic.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Min Num Unique Distribution Hubs cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Min Num Unique Distribution Hubs FAQ
Is this a minimum spanning tree problem?+
Possibly. If you're connecting all hubs and locations with minimum total cost or distance, yes. Use Kruskal's (sort edges, Union-Find) and count components. If it's about covering all locations with fewest hubs, it's closer to a set-cover greedy problem.
Do I need to precompute all pairwise distances?+
Check the input format. If you get coordinates or a distance matrix, yes. If the graph is already given as edges, no. Building the distance matrix upfront saves headaches during the algorithm.
What's the greedy trick?+
Sort edges by weight (distance/cost) and greedily union locations or hubs. Stop when all locations are covered or connected. Count the hubs used. This works if the problem allows a locally-optimal solution.
How do I know if this is Union-Find or BFS?+
Union-Find if you're merging components and counting them at the end. BFS if you're doing multi-source exploration from hubs or checking reachability. Read the constraint: 'connect all locations' usually means Union-Find.
What if I get stuck mid-OA?+
Assume greedy: sort by distance, pick hubs that cover the most uncovered locations, repeat. It won't always be optimal, but it's fast and often passes test cases. StealthCoder can verify the pattern and refine in real time.