Critical Bridges Problem

Critical Bridges Problem — ExecCode Hard DSA Practice

Solve the Critical Bridges problem on ExecCode. Free online hard DSA practice in Graph. Write and run code in Java, C++, Python — no signup required to run.

Problem description

An undirected connected graph of servers. A critical bridge is an edge whose removal increases the number of connected components. Return all such edges. Return each bridge as [u, v] with u < v, and sort the list of bridges lexicographically. You are given: n — node count, nodes are 0..n-1 connections — undirected edges Return sorted list of bridges. Do not return both [u,v] and [v,u].

Examples

Input {'n': 4, 'connections': [[0, 1], [1, 2], [2, 0], [1, 3]]}; Output [[1, 3]]. Input {'n': 2, 'connections': [[0, 1]]}; Output [[0, 1]]. Input {'n': 3, 'connections': [[0, 1], [1, 2], [2, 0]]}; Output []

Constraints

Graph may have cycles If there are no bridges, return []

Practice Critical Bridges free on ExecCode. Browse DSA problems, topic map, and placement guides.