n yes/no questions, each answered with 1 (yes) or 0 (no). It was filled in by m trainees and m coaches: trainees[i] holds the answers of trainee i, and coaches[j] the answers of coach j.
The compatibility of a trainee–coach pair is the number of questions they answered the same way. Each trainee must be assigned to exactly one coach so that every coach also ends up with exactly one trainee.
Return the largest possible total compatibility over all pairs.trainees=[[1, 0, 1], [0, 1, 1]], coaches=[[0, 1, 0], [1, 0, 1]] → 5
Pair the first trainee with the second coach (all 3 answers match) and the second trainee with the first coach (2 answers match): 3 + 2 = 5. The other assignment gives 0 + 1 = 1.
trainees=[[1, 1]], coaches=[[0, 1]] → 1
There is only one pair, and only the second answer matches.
trainees=[[1, 0], [1, 0], [0, 0]], coaches=[[1, 0], [0, 1], [1, 1]] → 4
The first coach suits both of the first two trainees (2 matches each) but can take only one. The best plan: trainee 1 to coach 1 (2), trainee 2 to coach 3 (1), trainee 3 to coach 2 (1), 4 in total.
m = trainees.length = coaches.lengthn = the length of every row of trainees and coachesm, n ≤ 80 or 1trainees=[[1, 0, 1], [0, 1, 1]], coaches=[[0, 1, 0], [1, 0, 1]]
5
Run checks the first 3 tests in your browser. Submit checks all 71 tests on the server, hidden ones included.