Clootrack | OA | Minimum roads to disconnect
Anonymous User
603

You are given an integer 'N', representing the number of cities, where each city is denoted by the number i where 1 <= i <= N. All adjacent cities are connected by a bidirectional road, which means that there is a road between city i and i+1 where 1 <= i < N.
You are also given an array of pairs of cities which needs to disconnected. Let us call this array 'D' and denote the length of this list by 'M'. You need to find the minimum number of roads to disconnect such that all the pairs of cities from 'D' are disconnected.

Constraints:
1 <= N <= 10^5
1 <= M <= 10^5

Ex:
N = 10
M = 5
D = [(3, 5), (4, 6), (2, 7), (1, 8), (7, 9)]

Ans: 2
Disconnect roads (4, 5) and (8, 9)

Comments (3)