FastPrepIs Graph Bipartite?
Problems/Is Graph Bipartite?

Is Graph Bipartite?

Microsoft logoMicrosoft● MediumNEW GRADFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two reports from Microsoft Data & Applied Science internships ask for detecting a bipartite graph. One gives an adjacency list and BFS. The other names a well-known problem. We chose the function signature and the limits. Our version is about 98% the same as the reported questions.

You are given an adjacency-list representation of an undirected graph. The vertices are numbered from 0 through graph.length - 1, and graph[u] lists every neighbor of vertex u.

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

The graph may be disconnected.

Function

isBipartite(graph: int[][]) → boolean

Examples

Example 1

graph = [[1,2,3],[0,2],[0,1,3],[0,2]]return = false

Vertices 0, 1, and 2 form an odd cycle.

Example 2

graph = [[1,3],[0,2],[1,3],[0,2]]return = true

One valid partition is {0, 2} and {1, 3}.

Example 3

graph = [[],[]]return = true

Two isolated vertices have no conflicting edge.

Constraints

  • 1 <= graph.length <= 500
  • Every neighbor is in the range from 0 through graph.length - 1.
  • No vertex lists itself, and a neighbor appears at most once in one adjacency list.
  • The graph is undirected: if v appears in graph[u], then u appears in graph[v].

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
  • Course SchedulePlaud · ONSITE INTERVIEW
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Evaluate DivisionPhonePe · ONSITE INTERVIEWPhonePe interview questions
  • Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Mouse and Cheese ReachabilityMeta · ONSITE INTERVIEWMeta interview questions
  • Number of IslandsTripjack · ONSITE INTERVIEWTripjack interview questions
  • Number of IslandsTekion · ONSITE INTERVIEWTekion interview questions

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public boolean isBipartite(int[][] graph) {
        // Write your code here.
    }
}
Checking account…