JuniorArray

Find the Maximum Divisibility Score

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.

Example 1
Inputnums = [2,9,15,50], divisors = [5,3,7,2]
Output2
Divisors 5, 3, and 2 all have divisibility score 2, so the smallest of them, 2, is returned.
Example 2
Inputnums = [4,7,9,3,9], divisors = [5,2,3]
Output3
Divisor 3 has the highest divisibility score of 3 because 9, 3, and 9 are divisible by 3.

Constraints

  • 1 <= nums.length, divisors.length <= 1000
  • 1 <= nums[i], divisors[i] <= 10^9

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate