Class Solution
-
- All Implemented Interfaces:
public final class Solution3494 - Find the Minimum Amount of Time to Brew Potions.
Medium
You are given two integer arrays,
skillandmana, of lengthnandm, respectively.In a laboratory,
nwizards must brewmpotions in order. Each potion has a mana capacitymana[j]and must pass through all the wizards sequentially to be brewed properly. The time taken by the <code>i<sup>th</sup></code> wizard on the <code>j<sup>th</sup></code> potion is <code>time<sub>ij</sub> = skilli * manaj</code>.Since the brewing process is delicate, a potion must be passed to the next wizard immediately after the current wizard completes their work. This means the timing must be synchronized so that each wizard begins working on a potion exactly when it arrives.
Return the minimum amount of time required for the potions to be brewed properly.
Example 1:
Input: skill = 1,5,2,4, mana = 5,1,4,2
Output: 110
Explanation:
As an example for why wizard 0 cannot start working on the 1<sup>st</sup> potion before time
t = 52, consider the case where the wizards started preparing the 1<sup>st</sup> potion at timet = 50. At timet = 58, wizard 2 is done with the 1<sup>st</sup> potion, but wizard 3 will still be working on the 0<sup>th</sup> potion till timet = 60.Example 2:
Input: skill = 1,1,1, mana = 1,1,1
Output: 5
Explanation:
Preparation of the 0<sup>th</sup> potion begins at time
t = 0, and is completed by timet = 3.Preparation of the 1<sup>st</sup> potion begins at time
t = 1, and is completed by timet = 4.Preparation of the 2<sup>nd</sup> potion begins at time
t = 2, and is completed by timet = 5.
Example 3:
Input: skill = 1,2,3,4, mana = 1,2
Output: 21
Constraints:
n == skill.lengthm == mana.length1 <= n, m <= 50001 <= mana[i], skill[i] <= 5000
-
-
Constructor Summary
Constructors Constructor Description Solution()
-