Trains the technique from
LeetCode 1971Find if Path Exists in 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 chilled-water plant is laid out as junctions junctions, labelled 0 through junctions - 1. The plumbing is given as pipes, where pipes[i] = [a, b] is one pipe that carries coolant in either direction between junction a and junction b.
A maintenance engineer wants to know whether coolant leaving the junction intake can arrive at the junction outlet by running through a sequence of pipes, using each junction at most once along the way.
Return true if such a run of pipes exists and false otherwise. intake and outlet may refer to the same junction, in which case no pipe has to be used at all.
No pipe joins a junction to itself, and no unordered pair of junctions is listed twice, though a pair may be written in either order.
Example 1
Coolant can take the pipe from 0 to 2 and then the pipe from 2 to 3, arriving at the outlet.
Example 2
Every pipe out of 2 leads to 1 or 0, and no pipe is listed from 0, 1 or 2 to either 3 or 4, so the outlet is never reached.
Example 3
The pipes [1, 0], [2, 1] and [3, 2] carry coolant in either direction, so the run 0, 1, 2, 3 is available.
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 coolant_reaches(junctions: int, pipes: list[list[int]], intake: int, outlet: int) -> bool:public boolean coolantReaches(int junctions, int[][] pipes, int intake, int outlet)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.