Amazon Online Assessment (OA) - DataCenter Critical Connection

Given a data center with n servers from 1 to n. To make the data center running, all servers must be connected, which means there exists at least one path between any pair of servers. Now we know there could be some critical connections broken which brings down the whole data center.

You need to write a program to find out all these broken critical connections. A server connection is a critical connection which when removed will make the whole data center disconnected.

Write a method to output all critical connections.

public static List<List<Integer>> findCriticalConn(int serversNum, int connectionsNum, int[][] connections)


The input consists of three arguments:

serversNum, the number of servers in the data center.

connectionsNum, the number of connections between the servers.

connections, a list of pairs representing the connections between two severs.


Return a list of integer pairs representing the critical connections. Output an empty array if there are no critical connections.


Example 1:


serversNum = 4

connectionsNum = 4

connections = [[1, 2], [1, 3], [3, 2], [3, 4]]

Output: [[3,4]]

There are one critical connections:

  1. Between server 3 and 4 If the connection [3, 4] breaks, then the network will be disconnected since servers 3 and 4 cannot communicate with the rest of the network. The remaining three connections are not critical.

Try it yourself