O46

Is Graph Bipartite?

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: BOOLEAN

Problem Statement & Objective

There is an undirected graph with n nodes. Return True if and only if it is bipartite.

Function Signature (Python)

is_graph_bipartite(graph: list[list[int]]) -> bool

Input & Output Contract

Output Rule:True veya False.

System Constraints

n == grafik.length
1 <= n <= 100
0 <= grafik[i].length < n
Kendine kenar veya çift kenar yoktur

Example Execution Walkthrough

grafik = [[1, 3], [0, 2], [1, 3], [0, 2]] (kare 4'lü halka) -> True
grafik = [[1, 2, 3], [0, 2], [0, 1, 3], [0, 2]] (üçgen içerir) -> False

Example Test Scenarios (3)

Example 1: 4'lü Döngü (Çift)
Input:[[[1,3],[0,2],[1,3],[0,2]]]
Expected Output:true
Example 2: Tek Uzunluklu Döngü
Input:[[[1,2,3],[0,2],[0,1,3],[0,2]]]
Expected Output:false
Example 3: Kenarsız
Input:[[[]]]
Expected Output:true
Loading Python Editor...
Input Parameters
[
  [
    [
      1,
      3
    ],
    [
      0,
      2
    ],
    [
      1,
      3
    ],
    [
      0,
      2
    ]
  ]
]
Expected Output
true