Ctrl K

The Divisor That Fits Most

Easy
You get two arrays of positive integers, values and candidates. For each candidate d, count how many elements of values are divisible by d with no remainder (repeated values count separately). Return the candidate with the highest count. If several candidates tie for the top, return the smallest of them.
Example 1
values=[12, 18, 25, 30], candidates=[4, 6, 5] → 6

Only 12 is divisible by 4; 12, 18 and 30 are divisible by 6; 25 and 30 by 5. 6 wins.

Example 2
values=[7, 11], candidates=[9, 2, 3] → 2

No value is divisible by any candidate, so they all score zero and the smallest one, 2, is returned.

Example 3
values=[10, 20, 40], candidates=[20, 10, 5] → 5
Constraints
  • 1 ≤ len(values), len(candidates) ≤ 1000
  • 1 ≤ values[i], candidates[j] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
values=[12, 18, 25, 30], candidates=[4, 6, 5]
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 125 tests on the server, hidden ones included.