This is a verified interview question from Deutsche-bank. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Vertices Stop Disappearing - Deutsche Bank Online Assessment MNNIT Allahabad" covers key patterns like Graphs.
"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? ### Example 1 Consider a graph with `N = 7` vertices and the following 6 edges: ```text (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: ```text 2 ``` ### Example 2 Consider the graph: ```text 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: ```text 1 ```  ### Function Signature ```java int solution(int N, int[] A, int[] B); ``` The function should return the number of seconds after which the vertices stop disappearing."
Join thousands of developers practicing for Deutsche-bank.