You are given an undirected graph. Your task is to determine whether the graph contains an odd-length cycle or an even-length cycle.
Return "Odd" if an odd-length cycle exists; otherwise, return "Even".
Input: V = 3, edges = [[0,1],[1,2],[2,0]]
Output: "Odd"
Explanation: The graph contains a cycle of length 3, which is odd.
Input: V = 4, edges = [[0,1],[1,2],[2,3],[3,0]]
Output: "Even"
Explanation: The graph contains a cycle of length 4, which is even.
Input: V = 2, edges = [[0,1]]
Output: "Even"
Explanation: The graph contains no odd-length cycle.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
3 3 0 1 1 2 2 0
Odd
3 2 0 1 1 2
false