Trains the technique from
LeetCode 2858Minimum Edge Reversals So Every Node Is ReachableThis 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 depot holds bays storage bays numbered 0 through bays - 1, joined by bays - 1 one-way corridors. Each entry corridors[i] = [a, b] is a corridor that a cart may drive only from bay a to bay b. Ignore the arrows and the layout is a tree: exactly one route of corridors joins any two bays.
Maintenance can retool a corridor so it runs only the other way, and each retooling is one work order.
For every bay s, report the fewest work orders that let a cart parked at bay s drive to every bay in the depot. Each bay is costed on its own: the corridors always start out as given, so a retooling planned for one bay does not carry over to the next.
Return an array of length bays whose entry s holds that count for bay s.
Example 1
From bay 0 a cart drives to bay 1 and bay 2 as the corridors stand, and one work order on the corridor between bay 3 and bay 2 lets it finish at bay 3. From bay 3 the cart drives straight to bay 2, then needs the corridor into bay 1 and the corridor into bay 0 retooled, which is two work orders.
Example 2
All three corridors run into bay 0, so a cart starting there needs all three retooled. A cart starting at bay 1 drives into bay 0 as things stand and needs the other two retooled.
Example 3
A cart at bay 1 already drives to bay 0, and a cart at bay 0 needs that single corridor retooled.
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 corridor_flips(bays: int, corridors: list[list[int]]) -> list[int]:public int[] corridorFlips(int bays, int[][] corridors)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.