Successful Pairs of Spells and Potions

You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the i^th spell and potions[j] represents the strength of the j^th potion.

You are also given an integer success. A spell and potion pair is considered successful if the product of their strengths is at least success.

Return an integer array pairs of length n where pairs[i] is the number of potions that will form a successful pair with the i^th spell.

Example 1
Inputspells = [5,1,3], potions = [1,2,3,4,5], success = 7
Output[4,0,3]
For spells 5, 1, and 3, there are respectively 4, 0, and 3 potions whose product with the spell is at least 7.
Example 2
Inputspells = [3,1,2], potions = [8,5,8], success = 16
Output[2,0,2]
For spells 3, 1, and 2, there are respectively 2, 0, and 2 potions whose product with the spell is at least 16.

Constraints

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

Asked at 7 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