Practice Is Graph Bipartite?
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
An undirected graph is supplied as adjacency lists graph, with nodes numbered 0 through n - 1. Lists contain no self-edges or duplicates, and each edge appears in both directions. The graph may be disconnected. Return whether all nodes can be split into two sets so that every edge joins nodes from different sets.
Source: Is Graph Bipartite? on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
graph = [[1,2,3],[0,2],[0,1,3],[0,2]]
Output
false
# Example 2
Input
graph = [[1,3],[0,2],[1,3],[0,2]]
Output
true
Constraints
graph.length == n
1 <= n <= 100
0 <= graph[u].length < n
0 <= graph[u][i] <= n - 1
graph[u] does not contain u.
All the values of graph[u] are unique.
If graph[u] contains v, then graph[v] contains u.
Related LeetCode Problems
Practice more problems similar to Is Graph Bipartite?.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.