Ctrl K

Pairs With a Scaled Divisor

Easy
You get two arrays of positive integers, amounts and bases, and a multiplier scale. A pair of indices (i, j) counts if amounts[i] is divisible by bases[j] · scale with no remainder. Return the number of pairs that count. Pairs with different indices are different pairs even when the numbers in them are equal.
Example 1
amounts=[6, 8, 12], bases=[1, 2, 3], scale=2 → 7

The scaled bases are 2, 4 and 6. 6 is divisible by 2 and 6, 8 by 2 and 4, and 12 by all three. That gives 2 + 2 + 3 = 7 pairs.

Example 2
amounts=[5, 9], bases=[2, 4], scale=3 → 0

The divisors to check are 6 and 12, and neither 5 nor 9 is divisible by them, so there are no pairs.

Example 3
amounts=[10, 10], bases=[5], scale=1 → 2
Constraints
  • 1 ≤ len(amounts), len(bases) ≤ 50
  • 1 ≤ amounts[i], bases[j] ≤ 10⁴
  • 1 ≤ scale ≤ 50
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasyThe Candidate With Most Votes EasyDoes Any Value Repeat EasyRepeat Within Reach EasyThe Lost Ticket Easy
loading Python…
Input
amounts=[6, 8, 12], bases=[1, 2, 3], scale=2
Expected
7

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