2644. Find the Maximum Divisibility Score Easy

@problem@discussion
#Array



1/**
2 * [2644] Find the Maximum Divisibility Score
3 *
4 * You are given two integer arrays nums and divisors.
5 * The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].
6 * Return the integer divisors[i] with the maximum divisibility score. If multiple integers have the maximum score, return the smallest one.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [2,9,15,50], divisors = [5,3,7,2]</span>
11 * Output: <span class="example-io">2</span>
12 * Explanation:
13 * The divisibility score of divisors[0] is 2 since nums[2] and nums[3] are divisible by 5.
14 * The divisibility score of divisors[1] is 2 since nums[1] and nums[2] are divisible by 3.
15 * The divisibility score of divisors[2] is 0 since none of the numbers in nums is divisible by 7.
16 * The divisibility score of divisors[3] is 2 since nums[0] and nums[3] are divisible by 2.
17 * As divisors[0], divisors[1], and divisors[3] have the same divisibility score, we return the smaller one which is divisors[3].
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">nums = [4,7,9,3,9], divisors = [5,2,3]</span>
22 * Output: <span class="example-io">3</span>
23 * Explanation:
24 * The divisibility score of divisors[0] is 0 since none of numbers in nums is divisible by 5.
25 * The divisibility score of divisors[1] is 1 since only nums[0] is divisible by 2.
26 * The divisibility score of divisors[2] is 3 since nums[2], nums[3] and nums[4] are divisible by 3.
27 * </div>
28 * <strong class="example">Example 3:
29 * <div class="example-block">
30 * Input: <span class="example-io">nums = [20,14,21,10], divisors = [10,16,20]</span>
31 * Output: <span class="example-io">10</span>
32 * Explanation:
33 * The divisibility score of divisors[0] is 2 since nums[0] and nums[3] are divisible by 10.
34 * The divisibility score of divisors[1] is 0 since none of the numbers in nums is divisible by 16.
35 * The divisibility score of divisors[2] is 1 since nums[0] is divisible by 20.
36 * </div>
37 *  
38 * Constraints:
39 * 
40 * 	1 <= nums.length, divisors.length <= 1000
41 * 	1 <= nums[i], divisors[i] <= 10^9
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/find-the-maximum-divisibility-score/
47// discuss: https://leetcode.com/problems/find-the-maximum-divisibility-score/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn max_div_score(nums: Vec<i32>, divisors: Vec<i32>) -> i32 {
53        0
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_2644() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.