You are given two integer arrays: nums and divisors. Your task is to find which divisor has the highest divisibility score.
The divisibility score of a divisor is simply the count of how many numbers in nums are divisible by that divisor. For example, if nums = [4, 7, 9, 3, 9] and we're checking divisor 3, we count how many numbers (4, 7, 9, 3, 9) are divisible by 3. In this case, both 9s and 3 are divisible by 3, giving us a score of 3.
Goal: Return the divisor with the maximum divisibility score. If there's a tie (multiple divisors have the same highest score), return the smallest divisor among them.
Example: nums = [4, 7, 9, 3, 9], divisors = [5, 2, 3]
• Divisor 5: score = 0 (no numbers divisible by 5)
• Divisor 2: score = 1 (only 4 is divisible by 2)
• Divisor 3: score = 3 (numbers 9, 3, 9 are divisible by 3)
Answer: 3 (highest score)
Input & Output
Constraints
- 1 ≤ nums.length, divisors.length ≤ 1000
- 1 ≤ nums[i], divisors[i] ≤ 109
- All divisors are positive integers
- Return the smallest divisor in case of tie