Skip to content

Commit 1cb5265

Browse files
committed
1947. Maximum Compatibility Score Sum: RETRY
1 parent f74cf04 commit 1cb5265

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

Diff for: src/solution/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1468,3 +1468,4 @@ mod s1943_describe_the_painting;
14681468
mod s1944_number_of_visible_people_in_a_queue;
14691469
mod s1945_sum_of_digits_of_string_after_convert;
14701470
mod s1946_largest_number_after_mutating_substring;
1471+
mod s1947_maximum_compatibility_score_sum;
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
*/
39+
pub 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+
46+
impl 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)]
55+
mod tests {
56+
use super::*;
57+
58+
#[test]
59+
#[ignore]
60+
fn test_1947_example_1() {
61+
let students = vec![vec![1, 1, 0], vec![1, 0, 1], vec![0, 0, 1]];
62+
let mentors = vec![vec![1, 0, 0], vec![0, 0, 1], vec![1, 1, 0]];
63+
64+
let result = 8;
65+
66+
assert_eq!(Solution::max_compatibility_sum(students, mentors), result);
67+
}
68+
69+
#[test]
70+
#[ignore]
71+
fn test_1947_example_2() {
72+
let students = vec![vec![0, 0], vec![0, 0], vec![0, 0]];
73+
let mentors = vec![vec![1, 1], vec![1, 1], vec![1, 1]];
74+
75+
let result = 0;
76+
77+
assert_eq!(Solution::max_compatibility_sum(students, mentors), result);
78+
}
79+
}

0 commit comments

Comments
 (0)