Skip to content
Decoder

Successful Pairs of Spells and Potions

Medium

Problem

You have two lists of positive integers, spells and potions, and a number success. A spell and a potion form a successful pair when the product of their strengths is at least success. For each spell, count how many potions it pairs with successfully, and return the counts as a list.

Example 1

Input
spells = [5, 1, 3], potions = [1, 2, 3, 4, 5], success = 7
Output
[4, 0, 3]

Example 2

Input
spells = [3, 1, 2], potions = [8, 5, 8], success = 16
Output
[2, 0, 2]

In the first example, spell 5 works with potions 2, 3, 4 and 5 (products 10 to 25), spell 1 with none, and spell 3 with potions 3, 4 and 5.

Constraints

  • 1 <= spells.length, potions.length <= 10^5
  • 1 <= spells[i], potions[i] <= 10^5
  • 1 <= success <= 10^10

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.