|
| 1 | +# 1947. Maximum Compatibility Score Sum |
| 2 | + |
| 3 | +There is a survey that consists of `n` questions where each question's answer is either `0` (no) or `1` (yes). |
| 4 | + |
| 5 | +The survey was given to `m` students numbered from `0` to `m - 1` and `m` mentors numbered from `0` to `m - 1`. The answers of the students are represented by a 2D integer array `students` where `students[i]` is an integer array that contains the answers of the `ith` student (0-indexed). The answers of the mentors are represented by a 2D integer array `mentors` where `mentors[j]` is an integer array that contains the answers of the `jth` mentor (0-indexed). |
| 6 | + |
| 7 | +Each student will be assigned to one mentor, and each mentor will have one student assigned to them. The compatibility score of a student-mentor pair is the number of answers that are the same for both the student and the mentor. |
| 8 | + |
| 9 | +- For example, if the student's answers were `[1, 0, 1]` and the mentor's answers were `[0, 0, 1]`, then their compatibility score is 2 because only the second and the third answers are the same. |
| 10 | + |
| 11 | +You are tasked with finding the optimal student-mentor pairings to maximize the sum of the compatibility scores. |
| 12 | + |
| 13 | +Given `students` and `mentors`, return the maximum compatibility score sum that can be achieved. |
| 14 | + |
| 15 | +Example 1: |
| 16 | + |
| 17 | +Input: students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]] |
| 18 | +Output: 8 |
| 19 | +Explanation: We assign students to mentors in the following way: |
| 20 | + |
| 21 | +- student 0 to mentor 2 with a compatibility score of 3. |
| 22 | +- student 1 to mentor 0 with a compatibility score of 2. |
| 23 | +- student 2 to mentor 1 with a compatibility score of 3. |
| 24 | + The compatibility score sum is 3 + 2 + 3 = 8. |
| 25 | + |
| 26 | +Example 2: |
| 27 | + |
| 28 | +Input: students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]] |
| 29 | +Output: 0 |
| 30 | +Explanation: The compatibility score of any student-mentor pair is 0. |
| 31 | + |
| 32 | +Constraints: |
| 33 | + |
| 34 | +- `m == students.length == mentors.length` |
| 35 | +- `n == students[i].length == mentors[j].length` |
| 36 | +- `1 <= m, n <= 8` |
| 37 | +- `students[i][k]` is either `0` or `1`. |
| 38 | +- `mentors[j][k]` is either `0` or `1`. |
0 commit comments