Skip to content

Commit 6936555

Browse files
committed
Add solution #3494
1 parent f529f97 commit 6936555

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,6 +2760,7 @@
27602760
3484|[Design Spreadsheet](./solutions/3484-design-spreadsheet.js)|Medium|
27612761
3487|[Maximum Unique Subarray Sum After Deletion](./solutions/3487-maximum-unique-subarray-sum-after-deletion.js)|Easy|
27622762
3491|[Phone Number Prefix](./solutions/3491-phone-number-prefix.js)|Easy|
2763+
3494|[Find the Minimum Amount of Time to Brew Potions](./solutions/3494-find-the-minimum-amount-of-time-to-brew-potions.js)|Medium|
27632764
3495|[Minimum Operations to Make Array Elements Zero](./solutions/3495-minimum-operations-to-make-array-elements-zero.js)|Hard|
27642765
3496|[Maximize Score After Pair Deletions](./solutions/3496-maximize-score-after-pair-deletions.js)|Medium|
27652766
3506|[Find Time Required to Eliminate Bacterial Strains](./solutions/3506-find-time-required-to-eliminate-bacterial-strains.js)|Hard|
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* 3494. Find the Minimum Amount of Time to Brew Potions
3+
* https://leetcode.com/problems/find-the-minimum-amount-of-time-to-brew-potions/
4+
* Difficulty: Medium
5+
*
6+
* You are given two integer arrays, skill and mana, of length n and m, respectively.
7+
*
8+
* In a laboratory, n wizards must brew m potions in order. Each potion has a mana capacity
9+
* mana[j] and must pass through all the wizards sequentially to be brewed properly. The
10+
* time taken by the ith wizard on the jth potion is timeij = skill[i] * mana[j].
11+
*
12+
* Since the brewing process is delicate, a potion must be passed to the next wizard
13+
* immediately after the current wizard completes their work. This means the timing must
14+
* be synchronized so that each wizard begins working on a potion exactly when it arrives.
15+
*
16+
* Return the minimum amount of time required for the potions to be brewed properly.
17+
*/
18+
19+
/**
20+
* @param {number[]} skill
21+
* @param {number[]} mana
22+
* @return {number}
23+
*/
24+
var minTime = function(skill, mana) {
25+
const result = new Array(skill.length + 1).fill(0);
26+
27+
for (let j = 0; j < mana.length; j++) {
28+
for (let i = 0; i < skill.length; i++) {
29+
result[i + 1] = Math.max(result[i + 1], result[i]) + mana[j] * skill[i];
30+
}
31+
for (let i = skill.length - 1; i > 0; i--) {
32+
result[i] = result[i + 1] - mana[j] * skill[i];
33+
}
34+
}
35+
36+
return result[skill.length];
37+
};

0 commit comments

Comments
 (0)