Interview Questions/Coding/Critical Router Audit

Critical Router Audit

Preview mode. Log in to edit, run, submit, and save progress.

Hard

Critical Router Audit

A datacenter map is an undirected network of routers. A router is considered critical if removing that router and all incident cables increases the number of connected regions in the remaining network. The network may already have more than one connected region. A router should be judged by whether its removal increases the total number of connected regions compared with the original network. Input Format: You are given n and an array edges, where each edge connects two routers. Output Format: Return the number of critical routers.

Examples

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

Explanation: Removing router(s) [1, 3] increases the number of connected components. Count = 2.

Approach hint

Discovery time and low-link values reveal separation points.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp