Trains the technique from
LeetCode 2045Second Minimum Time to Reach DestinationThis 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 yard has n depots numbered 1 through n. Each entry of edges is a pair of depots joined by a two-way run, and every run takes time minutes to travel. The yard is connected, so any depot can be reached from any other, and no run is listed twice.
Every depot has a gate that is open for change minutes, then shut for change minutes, over and over, starting open at minute 0. You may set off from a depot only while its gate is open; arriving is always allowed, and if you arrive while the gate is shut you wait for it to open again. Passing through a depot means leaving it, so the gate applies there too.
You set off from depot 1 at minute 0. Return the second smallest number of minutes in which depot n can be reached, counting only totals strictly larger than the smallest.
Example 1
Depot 7 is four runs away at the quickest and five runs away next, so the answer follows the five-run route. The clock reaches 21 after three runs, which lands in a shut stretch, so it waits until 27 before the fourth run and again before the fifth.
Example 2
The one run reaches depot 2 at minute 3. Going back and forth takes three runs, and the waits at the shut gates push that total out further.
Example 3
Every depot joins every other, so depot 4 is one run away and next two runs away. The gate shuts for the whole of minute 1, so the second run cannot start until minute 2.
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 second_minimum(n: int, edges: list[list[int]], time: int, change: int) -> int:public int secondMinimum(int n, int[][] edges, int time, int change)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.