Class Solution
java.lang.Object
g2201_2300.s2300_successful_pairs_of_spells_and_potions.Solution
2300 - Successful Pairs of Spells and Potions.<p>Medium</p>
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</sup></code> potion.</p>
<p>You are also given an integer <code>success</code>. A spell and potion pair is considered <strong>successful</strong> if the <strong>product</strong> of their strengths is <strong>at least</strong> <code>success</code>.</p>
<p>Return <em>an integer array</em> <code>pairs</code> <em>of length</em> <code>n</code> <em>where</em> <code>pairs[i]</code> <em>is the number of <strong>potions</strong> that will form a successful pair with the</em> <code>i<sup>th</sup></code> <em>spell.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> spells = [5,1,3], potions = [1,2,3,4,5], success = 7</p>
<p><strong>Output:</strong> [4,0,3]</p>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<p>0<sup>th</sup> spell: 5 * [1,2,3,4,5] = [5, <strong>10</strong> , <strong>15</strong> , <strong>20</strong> , <strong>25</strong> ]. 4 pairs are successful.</p>
</li>
<li>
<p>1<sup>st</sup> spell: 1 * [1,2,3,4,5] = [1,2,3,4,5]. 0 pairs are successful.</p>
</li>
<li>
<p>2<sup>nd</sup> spell: 3 * [1,2,3,4,5] = [3,6, <strong>9</strong> , <strong>12</strong> , <strong>15</strong> ]. 3 pairs are successful.</p>
</li>
</ul>
<p>Thus, [4,0,3] is returned.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> spells = [3,1,2], potions = [8,5,8], success = 16</p>
<p><strong>Output:</strong> [2,0,2]</p>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<p>0<sup>th</sup> spell: 3 * [8,5,8] = [<strong>24</strong> ,15, <strong>24</strong> ]. 2 pairs are successful.</p>
</li>
<li>
<p>1<sup>st</sup> spell: 1 * [8,5,8] = [8,5,8]. 0 pairs are successful.</p>
</li>
<li>
<p>2<sup>nd</sup> spell: 2 * [8,5,8] = [<strong>16</strong> ,10, <strong>16</strong> ]. 2 pairs are successful.</p>
</li>
</ul>
<p>Thus, [2,0,2] is returned.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == spells.length</code></li>
<li><code>m == potions.length</code></li>
<li><code>1 <= n, m <= 10<sup>5</sup></code></li>
<li><code>1 <= spells[i], potions[i] <= 10<sup>5</sup></code></li>
<li><code>1 <= success <= 10<sup>10</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]
successfulPairs
(int[] spells, int[] potions, long success)
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
successfulPairs
public int[] successfulPairs(int[] spells, int[] potions, long success)
-