3494. Find the Minimum Amount of Time to Brew Potions Medium
1/**
2 * [3494] Find the Minimum Amount of Time to Brew Potions
3 *
4 * You are given two integer arrays, skill and <font face="monospace">mana</font>, of length n and m, respectively.
5 * In a laboratory, n wizards must brew m potions in order. Each potion has a mana capacity mana[j] and must pass through all the wizards sequentially to be brewed properly. The time taken by the i^th wizard on the j^th potion is timeij = skill[i] * mana[j].
6 * 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.
7 * Return the minimum amount of time required for the potions to be brewed properly.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">skill = [1,5,2,4], mana = [5,1,4,2]</span>
12 * Output: <span class="example-io">110</span>
13 * Explanation:
14 * <table style="border: 1px solid black;">
15 * <tbody>
16 * <tr>
17 * <th style="border: 1px solid black;">Potion Number</th>
18 * <th style="border: 1px solid black;">Start time</th>
19 * <th style="border: 1px solid black;">Wizard 0 done by</th>
20 * <th style="border: 1px solid black;">Wizard 1 done by</th>
21 * <th style="border: 1px solid black;">Wizard 2 done by</th>
22 * <th style="border: 1px solid black;">Wizard 3 done by</th>
23 * </tr>
24 * <tr>
25 * <td style="border: 1px solid black;">0</td>
26 * <td style="border: 1px solid black;">0</td>
27 * <td style="border: 1px solid black;">5</td>
28 * <td style="border: 1px solid black;">30</td>
29 * <td style="border: 1px solid black;">40</td>
30 * <td style="border: 1px solid black;">60</td>
31 * </tr>
32 * <tr>
33 * <td style="border: 1px solid black;">1</td>
34 * <td style="border: 1px solid black;">52</td>
35 * <td style="border: 1px solid black;">53</td>
36 * <td style="border: 1px solid black;">58</td>
37 * <td style="border: 1px solid black;">60</td>
38 * <td style="border: 1px solid black;">64</td>
39 * </tr>
40 * <tr>
41 * <td style="border: 1px solid black;">2</td>
42 * <td style="border: 1px solid black;">54</td>
43 * <td style="border: 1px solid black;">58</td>
44 * <td style="border: 1px solid black;">78</td>
45 * <td style="border: 1px solid black;">86</td>
46 * <td style="border: 1px solid black;">102</td>
47 * </tr>
48 * <tr>
49 * <td style="border: 1px solid black;">3</td>
50 * <td style="border: 1px solid black;">86</td>
51 * <td style="border: 1px solid black;">88</td>
52 * <td style="border: 1px solid black;">98</td>
53 * <td style="border: 1px solid black;">102</td>
54 * <td style="border: 1px solid black;">110</td>
55 * </tr>
56 * </tbody>
57 * </table>
58 * As an example for why wizard 0 cannot start working on the 1^st potion before time t = 52, consider the case where the wizards started preparing the 1^st potion at time t = 50. At time t = 58, wizard 2 is done with the 1^st potion, but wizard 3 will still be working on the 0^th potion till time t = 60.
59 * </div>
60 * <strong class="example">Example 2:
61 * <div class="example-block">
62 * Input: <span class="example-io">skill = [1,1,1], mana = [1,1,1]</span>
63 * Output: <span class="example-io">5</span>
64 * Explanation:
65 * <ol>
66 * Preparation of the 0^th potion begins at time t = 0, and is completed by time t = 3.
67 * Preparation of the 1^st potion begins at time t = 1, and is completed by time t = 4.
68 * Preparation of the 2^nd potion begins at time t = 2, and is completed by time t = 5.
69 * </ol>
70 * </div>
71 * <strong class="example">Example 3:
72 * <div class="example-block">
73 * Input: <span class="example-io">skill = [1,2,3,4], mana = [1,2]</span>
74 * Output: 21
75 * </div>
76 *
77 * Constraints:
78 *
79 * n == skill.length
80 * m == mana.length
81 * 1 <= n, m <= 5000
82 * 1 <= mana[i], skill[i] <= 5000
83 *
84 */
85pub struct Solution {}
86
87// problem: https://leetcode.com/problems/find-the-minimum-amount-of-time-to-brew-potions/
88// discuss: https://leetcode.com/problems/find-the-minimum-amount-of-time-to-brew-potions/discuss/?currentPage=1&orderBy=most_votes&query=
89
90// submission codes start here
91
92impl Solution {
93 pub fn min_time(skill: Vec<i32>, mana: Vec<i32>) -> i64 {
94
95 }
96}
97
98// submission codes end
99
100#[cfg(test)]
101mod tests {
102 use super::*;
103
104 #[test]
105 fn test_3494() {
106 }
107}
108Back
© 2026 bowen.ge All Rights Reserved.