Maximum Bipartite Matching - Problem
Given a bipartite graph represented as an adjacency list, find the maximum matching. A matching is a set of edges where no two edges share a common vertex. A maximum matching is a matching that contains the largest possible number of edges.
The bipartite graph has vertices divided into two disjoint sets: left vertices (numbered 0 to n-1) and right vertices (numbered 0 to m-1). The input provides an adjacency list where graph[i] contains all right vertices that left vertex i is connected to.
Return the size of the maximum matching.
Input & Output
Example 1 — Complete Bipartite Graph
$
Input:
graph = [[1,2],[0,2],[0,1]]
›
Output:
3
💡 Note:
Perfect matching possible: Left 0→Right 1, Left 1→Right 2, Left 2→Right 0. All vertices matched.
Example 2 — Partial Matching
$
Input:
graph = [[0,1],[1],[0]]
›
Output:
2
💡 Note:
Maximum matching: Left 0→Right 0, Left 1→Right 1. Left 2 cannot be matched (Right 0 already taken).
Example 3 — No Edges
$
Input:
graph = [[],[],[]]
›
Output:
0
💡 Note:
No edges exist, so no matching is possible.
Constraints
- 1 ≤ graph.length ≤ 100
- 0 ≤ graph[i].length ≤ 100
- 0 ≤ graph[i][j] ≤ 99
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code