#2644
Easy Algorithms Find the maximum divisibility score
Array
51.7% acceptance
Feb 25, 2026
248
66
You are given two integer arrays nums and divisors.
The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].
Return the integer divisors[i] with the maximum divisibility score. If multiple integers have the maximum score,
return the smallest one.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn max_div_score(nums: Vec<i32>, divisors: Vec<i32>) -> i32 {
let mut best = divisors[0];
let mut best_score = 0usize;
for d in divisors {
let score = nums.iter().filter(|&&n| n % d == 0).count();
if score > best_score || (score == best_score && d < best) {
best_score = score;
best = d;
}
}
best
}
}