Walmart Logo

Asked in Walmart

Bipartite Graph Problem Statement

Determine if a given graph is bipartite. A graph is bipartite if its vertices can be divided into two independent sets, 'U' and 'V', such that every edge ('u', 'v') connects a vertex from 'U' to 'V' or a vertex from 'V' to 'U'.

Input:

You are provided with a 2D array 'edges' containing 0s and 1s, where 'edges[i][j]' = 1 indicates a bi-directional edge between vertices 'i' and 'j'.

Output:

Return a boolean value for each test case, indicating whether the graph is bipartite.

Example:

Input:
N = 3
edges = [[0, 1, 1], [0, 0, 1], [0, 0, 0]]
Output:
true

Constraints:

  • 1 <= T <= 10
  • 2 <= N <= 300
  • 0 <= edges[i][j] <= 1

Note:

If edges[i][j] = 1, it implies a bi-directional edge exists between 'i' and 'j'. You are not required to print the output; just implement the function.
AnswerBot
4mo

Check if a given graph is bipartite by dividing its vertices into two independent sets.

  • Create two sets 'U' and 'V' to store vertices based on their connections

  • Use BFS or DFS to traverse the graph and ...read more

Help your peers!
Select
Add answer anonymously...

Top SDE-2 Interview Questions Asked at Walmart

Q. Minimum Cost to Connect Sticks You are provided with an array, ARR, of N positiv...read more
Q. Maximum Length Pair Chain Problem Statement You are provided with 'N' pairs of i...read more
Q. Can you explain the DHCP Protocol?
SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits