Bipartite matching · Hard
A bounded assignment service pairs work items with compatible reviewers. A compatibility edge permits a pair but does not force it. Choosing the first free reviewer for every item can block a later item that has no alternative, so earlier choices may need to be reassigned.
Return the largest number of compatible pairs such that no left item or right reviewer is used more than once.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ left: integer, right: integer, edges: [integer, integer][] }
Fields
- left and right are the sizes of two separate sets with indexes 0..left-1 and 0..right-1.
- Each edge [u,v] permits pairing left item u with right item v. Duplicate edges do not create extra capacity.
Output
Return value
- Return only an integer maximum count, not the selected pairs.
- Either empty set or no edges gives zero. Isolated items remain unmatched; an arbitrary greedy matching is not sufficient.
Constraints
- 0 <= left,right <= 100; 0 <= edges.length <= 10000; all endpoints are valid.
- Do not mutate input. No external network or solver service is available.
Examples
Example 1
{
"edges": [
[
0,
0
],
[
0,
1
],
[
1,
0
]
],
"left": 2,
"right": 2
}Returns
2Example 2
{
"edges": [
[
0,
0
],
[
0,
0
],
[
1,
0
]
],
"left": 2,
"right": 1
}Returns
1Required complexity
O(left * (edges.length + right + 1)) time and O(left + right + edges.length) space