Medium
,Array
,Two Pointers
,Binary Search
,Sorting
2300. 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 ith spell and potions[j]
represents the strength of the jth 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 ith spell.
Example 1:
Example 2:
Constraints:
n
== spells.length
m
== potions.length
n
, m
<= 105spells[i]
, potions[i]
<= 105success
<= 1010Time:
Extra Space:
XD Apr 4, 2023
Sorting + Two Pointers
錯蠻多次的…只想到sorting後去做但還是一直TLE,樓上太神啦
Marsgoat Apr 21, 2023