Bipartite Graph
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write isBipartite(n, edges). An undirected graph has n nodes numbered 0 to n − 1, and each pair [a, b] in edges joins two different nodes. Return true if the nodes can be split into two groups so that every edge joins a node in one group to a node in the other, and false if not. The graph may come in several separate parts, and every part must split; a graph with no edges always does. For example, a square, isBipartite(4, [[0, 1], [1, 2], [2, 3], [3, 0]]), is true, and a triangle, isBipartite(3, [[0, 1], [1, 2], [2, 0]]), is false.
Your code must pass
- Accepts graphs that split in two
- Rejects a graph with an odd cycle
- Checks every part of a disconnected graph
- Accepts nodes with no edges