You are given an undirected graph consisting of N vertices, numbered from 0 to N-1, connected by M edges. The graph is described by two arrays, A and B, both of length M. A pair (A[K], B[K]), for K from 0 to M-1, describes an edge between vertex A[K] and vertex B[K].
Each second, every vertex with at most one connected edge disappears. Every edge which is connected to one of the disappearing vertices also disappears.
After how many seconds will the vertices stop disappearing?
Consider a graph with N = 7 vertices and the following 6 edges:
(0, 1), (1, 2), (2, 0), (1, 4), (4, 5), (4, 6)
After the first second, vertices 3, 5, and 6 will disappear.
After the next second, vertex 4 will disappear.
Vertices 0, 1, and 2 are connected with two edges each, so none of them will disappear.
Therefore, the function should return:
2
Consider the graph:
N = 4
A = [0, 1, 2, 3]
B = [1, 2, 0, 0]
After the first second, vertex 3 will disappear.
Therefore, the function should return:
1

int solution(int N, int[] A, int[] B);
The function should return the number of seconds after which the vertices stop disappearing.
Arista • Pending
Arista • Pending
BlackRock • Pending
BlackRock • Pending