Code RoomCritical hub corridor
EasyPrep Room Coding #4798

Critical hub corridor

CodingAlgorithms & data structuresEntry–Mid~18 min

A parcel network moves cartons between hubs numbered 0 upward. routes[i] lists every hub reachable directly from hub i along a one way lane, so a lane runs both ways only when both directions are listed. A carton never visits a hub twice, so consider only the routes from start to finish that repeat no hub. Some hubs sit on every one of those routes whatever lanes the carton takes, and those are the ones that shut the corridor down when they close. Return them in ascending order. Both endpoints count, since every route runs through them, and when start and finish are the same hub that single hub is the whole route. Return an empty list when no route exists at all. The network holds at most twelve hubs, and it may list a lane twice or a lane from a hub back to itself.

Implement
choke_point_hubs(routes: list[list[int]], start: int, finish: int) → list[int]
Examples
in[[[1,2],[3],[3],[4],[]],0,4]out[0,3,4]
in[[[1,2],[2],[]],0,2]out[0,2]
in[[[1],[],[]],0,2]out[]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 18 min
InputExpectedGot
[[[1,2],[3],[3],[4],[]],0,4][0,3,4]not run yetsample
[[[1,2],[2],[]],0,2][0,2]not run yetsample
[[[1],[],[]],0,2][]not run yetsample