Microsoft Internship OA '23
Anonymous User
294

I am given undirected graph that consists 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]) describes edge between A[k] and B[k] for k from 0 to M-1.

Each second every vertex with at most 1 edge connected to disappears.Every edge which is connected to one of disappearing vertices also disappears.

After how many seconds will the vertices stop disappearing.

For N=7, ((0,1),(1,2),(2,0),(1,4),(4,5),(4,6)) answer should be 2.

Comments (5)