First Pipeline That Closes a Loop

Asked at Two Sigma · Coding Questions · Difficulty: Medium · Last asked Jul 15, 2026

Pipelines are laid between cities one at a time, in the order of a list. Each pipeline joins two cities directly and can carry water in both directions. A pipeline is redundant when the cities it joins are already connected, directly or through other pipelines, by the pipelines laid before it. Find the first redundant pipeline in the list.

Loading the problem…