Practice Add Edges to Make Degrees of All Nodes Even
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
There is an undirected graph consisting of n nodes numbered from 1 to n. You are given the integer n and a 2D array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi. The graph can be disconnected. You can add at most two additional edges (possibly none) to this graph so that there are no repeated edges and no self-loops. Return true if it is possible to make the degree of each node in the graph even, otherwise return false. The degree of a node is the number of edges connected to it.
Source: Add Edges to Make Degrees of All Nodes Even on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 5, edges = [[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]]
true
# Example 2
n = 4, edges = [[1,2],[3,4]]
true
# Example 3
n = 4, edges = [[1,2],[1,3],[1,4]]
false
Constraints
Related LeetCode Problems
Practice more problems similar to Add Edges to Make Degrees of All Nodes Even.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.