S
All challenges
Practice
Home
Blog
Practice
Examples
Feedback
Detect Cycle in Undirected Graph
00:00
Start
00:00
Sign in
Problem
Hints
3
Solution
History
Medium
Graph
DFS
Union-Find
Cycle Detection
Amazon
Microsoft
Detect if an undirected graph has a cycle using DFS or Union-Find.
Examples
Example 1
Input →
0-1-2-0 (triangle)
Output →
True
Example 2
Input →
0-1-2-3 (path)
Output →
False
Example 3
Input →
single edge 0-1
Output →
False
JavaScript
Python
Java (Coming soon)
C (Coming soon)
C++ (Coming soon)
Reset
Run
Submit
Cases
Results