Bipartite Graph Problem
Check whether a given graph is bipartite or not. Return true
if the graph's vertices can be divided into two independent sets, ‘U’ and ‘V’, such that every edge (‘u’, ‘v’) either connects a vertex from ‘U’ to ‘V’ or a vertex from ‘V’ to ‘U’.
You are provided with a 2D array edges
consisting of 0s and 1s, where edges[i][j] = 1
indicates a bi-directional edge between vertices i
and j
. Edge existence implies both (i → j)
and (j → i)
.
Input:
‘N’ = 3 ‘edges’ = [[0, 1, 1], [0, 0, 1], [0, 0, 0]]
Output:
True or False (whether the graph is bipartite)
Example:
Given:
‘N’ = 3 ‘edges’ = [[0, 1, 1], [0, 0, 1], [0,0,0]]
Explanation:
The function should return whether the input graph is bipartite.
Constraints:
1 <= ‘T’ <= 10
2 <= ‘N’ <= 300
0 <= ‘edges[i][j]’ <= 1
- Time Limit: 1 second
Note:
Do not print the outcome, only implement the function to return the necessary result.

AnswerBot
4mo
Check if a given graph is bipartite by dividing vertices into two independent sets.
Use BFS or DFS to traverse the graph and assign colors to vertices to check for bipartiteness.
If an edge connects ver...read more
Help your peers!
Add answer anonymously...
Infosys SDE interview questions & answers
A SDE was asked 10mo agoQ. What is annotation in Spring Boot?
A SDE was asked Q. Count Inversions Problem Statement Given an integer array ARR of size N containi...read more
A SDE was asked Q. Boundary Traversal of Binary Tree Given a binary tree of integers, your task is ...read more
Popular interview questions of SDE
A SDE was asked 10mo agoQ1. What is annotation in Spring Boot?
A SDE was asked Q2. Count Inversions Problem Statement Given an integer array ARR of size N containi...read more
A SDE was asked Q3. Boundary Traversal of Binary Tree Given a binary tree of integers, your task is ...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

