Hard · Graphs

Critical Connections in a Network

Given n servers numbered 0 to n − 1 and a list of undirected connections that form a connected network, return every critical connection in any order. A connection is critical when removing it leaves some server unable to reach another.

Examples

Example 1

{
  "adj": [
    [1, 2],
    [0, 2],
    [1, 0, 3],
    [2, 4],
    [3]
  ]
}

Output: [[3, 4], [2, 3]]

Example 2

{
  "adj": [
    [1, 2],
    [0, 2, 3],
    [0, 1],
    [1, 4, 5],
    [3, 5],
    [3, 4]
  ],
  "pos": [
    [36, 45],
    [106, 110],
    [36, 175],
    [194, 110],
    [264, 45],
    [264, 175]
  ]
}

Output: [[1, 3]]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Graphs problems