1947. Maximum Compatibility Score Sum Medium
1/**
2 * [1947] Maximum Compatibility Score Sum
3 *
4 * There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes).
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 i^th 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 j^th mentor (0-indexed).
6 * 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.
7 *
8 * For example, if the student's answers were [1, <u>0</u>, <u>1</u>] and the mentor's answers were [0, <u>0</u>, <u>1</u>], then their compatibility score is 2 because only the second and the third answers are the same.
9 *
10 * You are tasked with finding the optimal student-mentor pairings to maximize the sum of the compatibility scores.
11 * Given students and mentors, return the maximum compatibility score sum that can be achieved.
12 *
13 * Example 1:
14 *
15 * Input: students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]]
16 * Output: 8
17 * Explanation: We assign students to mentors in the following way:
18 * - student 0 to mentor 2 with a compatibility score of 3.
19 * - student 1 to mentor 0 with a compatibility score of 2.
20 * - student 2 to mentor 1 with a compatibility score of 3.
21 * The compatibility score sum is 3 + 2 + 3 = 8.
22 *
23 * Example 2:
24 *
25 * Input: students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]]
26 * Output: 0
27 * Explanation: The compatibility score of any student-mentor pair is 0.
28 *
29 *
30 * Constraints:
31 *
32 * m == students.length == mentors.length
33 * n == students[i].length == mentors[j].length
34 * 1 <= m, n <= 8
35 * students[i][k] is either 0 or 1.
36 * mentors[j][k] is either 0 or 1.
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/maximum-compatibility-score-sum/
42// discuss: https://leetcode.com/problems/maximum-compatibility-score-sum/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn max_compatibility_sum(students: Vec<Vec<i32>>, mentors: Vec<Vec<i32>>) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_1947() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.