30 · Advanced Graphs: Euler Paths, Bridges & SCCs

#1192 Critical Connections in a Network

Hardsolve on LeetCode ↗

frequently reported atAmazonGoogleMeta

the problem

In plain words

There are n servers, numbered 0 to n − 1, joined by two-way cables connections[i] = [a, b], and every server can reach every other one. A cable is critical if removing it leaves at least one pair of servers unable to reach each other. Return all critical cables, in any order.

in n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]

out [[1,3]]

0, 1 and 2 form a loop, so none of those cables matters alone. Cable 1–3 is the only way to reach 3. [[3,1]] is accepted too.

in n = 2, connections = [[0,1]]

out [[0,1]]

  • 2 ≤ n ≤ 10⁵
  • n − 1 ≤ connections.length ≤ 10⁵
  • a ≠ b, and no cable is listed twice
  • The network is connected

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #1489
    2. #684
      Redundant Connection
      Mediumin Union-Find & MST
    3. #200
      Number of Islands
      Mediumin Graphs