Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Is the graph bipartite?

    Is the graph bipartite?

    Mediumgraphbfsdfsgraph coloring

    graph[i] lists the neighbours of node i (edges go both ways). Return true if the nodes can be split into two teams so that every edge joins nodes from different teams. The graph may be disconnected.

    Example 1

    Input:  graph = [[1,3],[0,2],[1,3],[0,2]]
    Output: true

    Example 2

    Input:  graph = [[1,2,3],[0,2],[0,1,3],[0,2]]
    Output: false

    Constraints

    • 1 ≤ n ≤ 100
    • graph[i] has no self-loops or repeats
    • If j is in graph[i], i is in graph[j]

    Submit checks your solution against 9 tests, including hidden ones.

    /**
     * @param {int[][]} graph
     * @return {bool}
     */
    function isBipartite(graph) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.