Skip to interview prep
Apexed
Problem list121 / 125

121. Bridges in an Undirected Graph

HardGraphs

An undirected graph has n vertices (0 to n − 1) and edges as pairs [u, v], with no duplicate edges or self-loops. A bridge is an edge whose removal increases the number of connected components.

Return every bridge as [u, v] with u < v, and sort the list ascending by u, then by v.

Example 1

Input: n = 4, edges = [[0,1],[1,2],[2,0],[1,3]]
Output: [[1, 3]]

Constraints

  • 1 ≤ n ≤ 10⁴
  • 0 ≤ edges.length ≤ 10⁴

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 6 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Bridges in an Undirected Graph — coding interview practice — Apexed