565. Maximum Number of Accepted Invitations
There are m boys and n girls. Each boy can invite at most one girl, and each girl can accept at most one invitation. You are given a m*n binary matrix grid where grid[i][j] is 1 if the ith boy can invite the jth girl, and 0 otherwise.
Return the maximum number of accepted invitations such that no two boys invite the same girl and no two girls accept invitations from the same boy.
Example 1:
Input : grid = [[1,1,1],[1,0,1],[0,0,1]]
Output : 3
Explanation :
The invitations are sent as follows:
- The 1st boy invites the 2nd girl.
- The 2nd boy invites the 1st girl.
- The 3rd boy invites the 3rd girl.
Example 2:
Input : grid = [[1,0,1,0],[1,0,0,0],[0,0,1,0],[1,1,1,0]]
Output : 3
Explanation :
The invitations are sent as follows:
- The 1st boy invites the 3rd girl.
- The 2nd boy invites the 1st girl.
- The 3rd boy invites no one.
- The 4th boy invites the 2nd girl.
Now Your Turn!
Pick the correct output for the given inputInput : grid = [[1,1,0],[1,0,1],[0,1,1]]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- grid.length == m
- grid[i].length == n
- 1 <= m, n <= 200
- grid[i][j] is either 0 or 1.