Find the Maximum Divisibility Score - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [4,7,9,3,9], divisors = [5,2,3]
›
Output:
3
💡 Note:
Divisor 5: no numbers divisible (score 0). Divisor 2: only 4 is divisible (score 1). Divisor 3: numbers 9, 3, 9 are divisible (score 3). Maximum score is 3, so return 3.
Example 2 — Tie Case
$
Input:
nums = [20,14,21,10], divisors = [5,7,5]
›
Output:
5
💡 Note:
Divisor 5: numbers 20, 10 are divisible (score 2). Divisor 7: numbers 14, 21 are divisible (score 2). Both have score 2, but 5 < 7, so return 5.
Example 3 — Single Element
$
Input:
nums = [12], divisors = [10,16]
›
Output:
10
💡 Note:
Divisor 10: 12 is not divisible by 10 (score 0). Divisor 16: 12 is not divisible by 16 (score 0). Both have score 0, but 10 < 16, so return 10.
Constraints
- 1 ≤ nums.length, divisors.length ≤ 1000
- 1 ≤ nums[i], divisors[i] ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input Arrays
nums array and divisors array
2
Count Scores
For each divisor, count how many numbers are divisible
3
Find Maximum
Return divisor with highest score (smallest if tied)
Key Takeaway
🎯 Key Insight: Count how many numbers each divisor can divide, return the divisor with the highest count
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code