DSA interview question
In a road network, some intersections are single points of failure: if an intersection closes, part of the city is cut off. These vertices are articulation points (cut vertices). Tarjan's DFS with discovery times and low-links finds them all in one pass:
low[v] ≥ tin[u], meaning v's subtree can't reach above u without going through u.Example: 5 vertices, edges 0-1, 1-2, 2-0, 1-3, 3-4 → [1, 3].
vector<int> articulationPoints(int V, const vector<pair<int, int>>& edges); // sorted, or {-1} if none
Input (V, edges) | Output | Explanation |
|---|---|---|
(5, [[0,1],[1,2],[2,0],[1,3],[3,4]]) | [1, 3] | 1 separates {3, 4}; 3 separates {4} |
(4, [[0,1],[1,2],[2,3]]) | [1, 2] | Interior vertices of a path |
(5, [[0,1],[0,2],[0,3],[0,4]]) | [0] | The centre of a star |
(3, [[0,1],[1,2],[2,0]]) | [-1] | A cycle has none |
(2, [[0,1]]) | [-1] |
(Confirm: the graph is undirected and simple; it may be disconnected; return [−1] when there are no articulation points.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in