#1947
Maximum Compatibility Score Sum
specialist · 645 · lc medium +30 · verified · 64.4% accepted · 832 likes · top 68%
Description
There are m students and m mentors. Each pair (i, j) has a compatibility score equal to the number of matching answers between student i and mentor j across n binary survey questions.
Assign each student to exactly one mentor and each mentor to exactly one student to maximize the total compatibility score.
Return that maximum score.
Example 1:
Input: students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]]
Output: 8
Explanation: We assign students to mentors in the following way:
- student 0 to mentor 2 with a compatibility score of 3.
- student 1 to mentor 0 with a compatibility score of 2.
- student 2 to mentor 1 with a compatibility score of 3.
The compatibility score sum is 3 + 2 + 3 = 8.
Example 2:
Input: students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]]
Output: 0
Explanation: The compatibility score of any student-mentor pair is 0.
Code
1
2
3