medium

Is Graph Bipartite?

Given an undirected graph as an adjacency list, decide whether its nodes can be split into two groups such that every edge connects a node from one group to the other.

Constraints
  • 1 ≤ n ≤ 100
  • No self-loops or parallel edges
  • The graph may be disconnected
Examples
in: graph = [[1,3],[0,2],[1,3],[0,2]]
out: true
in: graph = [[1,2,3],[0,2],[0,1,3],[0,2]]
out: false

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.