Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6560 |

@blackshadows | 6400 |

@mb1973 | 5777 |

@Quandray | 5271 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4356 |

@sanjay05 | 3762 |

@mantu_singh | 3638 |

@gfgaccount | 3601 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@anish5256 | 991 |

@vimleshpratapsingh321 | 980 |

@skj7 | 871 |

@akhileshkumar562002 | 862 |

@pradeeppatidar1999 | 840 |

@kanewilliamson123 | 837 |

@pd420786 | 813 |

@infilooop | 800 |

@bunnybug320 | 796 |

@smitabose7826 | 784 |

@virgat | 768 |

Complete Leaderboard |

Kamar-taj is a place where "The Ancient One" trains people to protect earth from other dimensions.

The earth is protected by **N** sanctums, destroying any of it will lead to invasion on earth.

The sanctums are connected by **M** bridges.

Now , you being on dormammu's side , want to find the number of sanctum destroying which will disconnect the sanctums.

**Example 1:**

**Input:**
N = 5, M = 5
arr[] = {{1,2},{1,3},{3,2},{3,4},{5,4}}
**Output :** 2
**Explanation:**
1.Removing 1 will not make graph disconnected
(2--3--4--5).
2.Removing 2 will also not make
graph disconnected(1--3--4--5).
3.Removing 3 makes graph disconnected
(1--2 and 4--5).
4.Removing 4 makes graph disconnected
(1--2--3--1 and 5).
5.Removing 5 also doesn't makes
graph disconnected(3--1--2--3--4).
6. Therefore,there are two such vertices,
3 and 4,so the answer is 2.

**Example 2:**

**Input :**
N = 2, M = 1
arr[] = {{1, 2}}**
Output :** 0

**Your Task:**

This is a function problem. The input is already taken care of by the driver code. You only need to complete the function **doctorStrange()** that takes a number of nodes **(N)**, a number of edges **(M),** a 2-D matrix that contains connection between nodes **(graph)**, and return the number of sanctums when destroyed will disconnect other sanctums of Earth.

**Expected Time Complexity:** O(N + M).

**Expected Auxiliary Space:** O(N + M).

**Constraints:**

1 ≤ n ≤ 30000

1 ≤ m ≤ 30000

1 ≤ u, v ≤ n

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Doctor Strange

...