Ctrl K

Lots and Packs

Medium
A warehouse holds lots of goods: lots[i] is the number of units in lot i. There are also pack types: pack j holds packs[j] units, and packs ship in blocks of factor, so a block of type j is packs[j] · factor units. A pair (i, j) fits if lot lots[i] can be split entirely into blocks of type j with nothing left over. Return the number of fitting pairs. Pairs with different indices count separately even when their numbers are equal. The arrays can be long, so checking every pair will be too slow.
Example 1
lots=[12, 18, 7], packs=[2, 3, 6], factor=2 → 4

Blocks hold 4, 6 and 12 items. Lot 12 splits into blocks of 4, 6 or 12, lot 18 only into blocks of 6, and 7 into none: 3 + 1 = 4 pairs.

Example 2
lots=[5, 5], packs=[1, 1], factor=5 → 4

Each of the two lots splits into blocks of 5 for each of the two packs: 2 · 2 = 4 pairs.

Example 3
lots=[9], packs=[2], factor=3 → 0

A block of 6 does not divide a lot of 9.

Constraints
  • 1 ≤ len(lots), len(packs) ≤ 10⁵
  • 1 ≤ lots[i], packs[j] ≤ 10⁶
  • 1 ≤ factor ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSudoku Board Without Clashes MediumAnagram Buckets MediumZero Out the Crosses MediumTree From Pre-Order and In-Order Walks MediumTree From In-Order and Post-Order Walks Medium
loading Python…
Input
lots=[12, 18, 7], packs=[2, 3, 6], factor=2
Expected
4

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