Trains the technique from
LeetCode 1791Find Center of Star GraphThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A courier company runs n depots labelled 1 through n. One of them is the hub: every other depot is joined to the hub by its own road, and there are no other roads, so the network holds exactly n - 1 roads and each road has the hub at one end.
roads lists those roads in no particular order. roads[i] = [a, b] records a road running between depot a and depot b, and the two ends of a road are always different depots.
Return the label of the hub depot.
Example 1
There are four roads, so the network has five depots. Depot `4` is written on every road, and no other depot is.
Example 2
Nine roads means ten depots. Depot `7` shares a road with each of the other nine depots, and every road listed has `7` on one side.
Example 3
The smallest network of this shape has three depots and two roads. Depot `3` appears on both roads.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def hub_depot(roads: list[list[int]]) -> int:public int hubDepot(int[][] roads)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.