m mentors and has just hired n interns. The m × n table fits says who suits whom: fits[i][j] = 1 if mentor i can supervise intern j, and 0 otherwise.
Each mentor takes at most one intern, and each intern gets at most one mentor. A pair can only be formed by a mentor and an intern who suit each other.
Return the largest number of mentor–intern pairs that can be formed at the same time.fits=[[1, 1, 0], [1, 0, 0], [0, 1, 1]] → 3
Mentor 1 fits only intern 0, so mentor 0 takes intern 1 and mentor 2 takes intern 2. That makes 3 pairs.
fits=[[1, 0], [1, 0], [1, 1]] → 2
Mentors 0 and 1 both want only intern 0, so just one of them gets a pair. Mentor 2 takes intern 1. That is 2 in total.
fits=[[0, 0, 0]] → 0
The only mentor fits nobody.
fits[i][j] is 0 or 1fits=[[1, 1, 0], [1, 0, 0], [0, 1, 1]]
3
Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.