Ctrl K

Mentors and Interns

Medium
A company has 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.
Example 1
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.

Example 2
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.

Example 3
fits=[[0, 0, 0]] → 0

The only mentor fits nobody.

Constraints
  • 1 ≤ m, n ≤ 200
  • fits[i][j] is 0 or 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsShortest Path of a Rolling Ball MediumLongest Uphill Walk HardBall Into the Hole HardUphill-Only Walks HardWord Traced on a Letter Grid Medium
loading Python…
Input
fits=[[1, 1, 0], [1, 0, 0], [0, 1, 1]]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.