FastPrepCheck Bipartite Graph
Problems/Check Bipartite Graph

Check Bipartite Graph

InMobi logoInMobi● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an InMobi new grad online assessment. Our version is about 99% the same as the reported InMobi online coding test prompt. The report treats an undirected edge as present when either matching matrix entry is 1. That includes matrices that store only one triangle.

You are given a square binary matrix edges describing an undirected graph with vertices numbered from 0 through n - 1.

Vertices i and j are connected when edges[i][j] == 1 or edges[j][i] == 1. This convention allows an edge to be recorded in either half of the matrix.

Return true if the vertices can be divided into two groups such that every edge joins vertices from different groups. Otherwise, return false.

Function

isGraphBipartite(edges: int[][]) → boolean

Examples

Example 1

edges = [[0,1,0,0],[0,0,0,1],[0,0,0,0],[0,0,0,0]]return = true

The only edges are 0-1 and 1-3. One valid partition is {0, 3} and {1, 2}.

Example 2

edges = [[0,1,1],[0,0,1],[0,0,0]]return = false

Vertices 0, 1, and 2 form an odd cycle, so two groups are impossible.

Example 3

edges = [[0,1,0,1,0],[1,0,1,0,0],[0,1,0,1,0],[1,0,1,0,0],[0,0,0,0,0]]return = true

The four connected vertices form an even cycle, and vertex 4 is isolated. Every component is bipartite.

Constraints

  • 2 <= edges.length <= 300
  • edges[i].length == edges.length
  • edges[i][j] is either 0 or 1.
  • edges[i][i] == 0
  • An undirected edge is present when either edges[i][j] or edges[j][i] is 1.

More InMobi Online Assessment questions

  • Validate a Bracket SequenceOA · Seen Oct 2026
  • Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
  • Maximum Subarray with Start and End WindowsOA · Seen Oct 2026
  • Minimum Service Cold StartsOA · Seen Oct 2026
  • Range Maximum Subarray Sum QueriesOA · Seen Oct 2026
  • Connected Components with Divisor ThresholdOA · Seen Aug 2026
  • Maximize Impression ValueOA · Seen Aug 2026
  • Supply Path OptimizationOA · Seen Aug 2026
  • Delivery ServiceOA · Seen Jun 2026
  • Shared InterestOA · Seen Jun 2026

Similar questions at other companies

  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Shortest Atom Action PathOpenAI · OAOpenAI interview questions
  • Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
  • Count Islands with DFS and BFSVisa · OAVisa interview questions
  • Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Count One Groups by SizeAgoda · OAAgoda interview questions
  • Ascend Vertical Wall (For off-campus 2025 batch hiring :)Uber · OAUber interview questions
  • Grid ExplorationIMC Trading · OAIMC Trading interview questions
  • Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
  • Nearest Different Maze Exit for a SnakeIntuit · OAIntuit interview questions
All InMobi interview questionsSee InMobi hiring insights
Saved
class Solution {
    public boolean isGraphBipartite(int[][] edges) {
        // write your code here.
    }
}
Checking account…