Back to problems

Distance from Each Node to the Cycle in an Undirected Graph

Algorithm · Microsoft · Hard

Examples Example 1 Example 2 Requirements You are given a connected, undirected graph described by (n, edges). It has one and only one simple cycle, with tree branches attached to vertices on that cycle. Produce an array dist of size n such that dist[v] equals the minimum number of edges from vertex v to any vertex belonging to the cycle. This has appeared as one 45-minute coding exercise. After an initial solution, the interviewer may request that DFS be written…

Checking your access…