Company: Samsung

Difficulty: medium

Problem Statement

Check Whether a Graph is Bipartite Given an undirected graph with V vertices (numbered from 0 to V-1 ) and E edges, check whether the graph is bipartite or not. A bipartite graph can be colored with two colors such that no two adjacent vertices share the same color . This means we can divide the graph's vertices into two distinct sets where: All edges connect vertices from one set to vertices in the other set. No edges exist between vertices within the same set. The graph is not necessarily connected. Input Format The first line contains two space-separated integers V and E - the number of vertices and the number of edges. Each of the next E lines contains two space-separated integers u and v , denoting an undirected edge between vertex u and vertex v . Output Format Print true if the graph is bipartite, otherwise print false . Constraints 1 <= V <= 10000 0 <= E <= 12000 0 <= u, v <= V-1 u != v (no self-loops) No edge is repeated (the graph is simple) Examples ### Exa

More Samsung OA questionsInterview experiences