Company: Wipro-Project engineer-on campus_23may
Difficulty: medium
You are given an undirected graph consisting of N vertices, numbered from 0 to N-1 , connected with 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 edge connected to it 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 following 6 edges: (0, 1), (1, 2), (2, 0), (1, 4), (4, 5) and (4, 6). After the first second, vertices 3, 5, and 6 (marked red in the picture above) will disappear. After the next second vertex 4 will disappear and only vertices 0, 1 and 2 will be left. All three remaining vertices are connected to two edges, so none of them will ever disappear and the answer is 2. Write a function: class Solution { public int solution(int N, int[] A, int[] B); } that, given