Tap here to switch tabs
Problem
Submissions

Problem: Find the Minimum Amount of Time to Brew Potions

med
30 min
Try to solve the Find the Minimum Amount of Time to Brew Potions problem.

Statement

You are given two integer arrays skill and mana. There are n wizards arranged in a fixed order, where wizard i has skill value skill[i], and there are m potions to brew in order, where potion j has mana requirement mana[j].

Brewing a single potion must be done by all wizards sequentially from wizard 00 to wizard n−1n - 1. If wizard i works on potion j, it takes skill[i] * mana[j] units of time.

Each wizard can work on at most one potion at a time, and each potion can be worked on by at most one wizard at a time. A potion must move from wizard i to wizard i + 1 immediately after wizard i finishes, meaning the start times must be chosen so that no potion ever waits between wizards.

Return the minimum possible time at which all m potions have finished brewing (after wizard n−1n - 1 completes the last potion).

Constraints:

  • n == skill.length

  • m == mana.length

  • 1≤‘n‘,‘m‘≤50001 \leq `n`, `m` \leq 5000

  • 1≤‘mana[i]‘,‘skill[i]‘≤50001 \leq `mana[i]`, `skill[i]` \leq 5000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Minimum Amount of Time to Brew Potions

med
30 min
Try to solve the Find the Minimum Amount of Time to Brew Potions problem.

Statement

You are given two integer arrays skill and mana. There are n wizards arranged in a fixed order, where wizard i has skill value skill[i], and there are m potions to brew in order, where potion j has mana requirement mana[j].

Brewing a single potion must be done by all wizards sequentially from wizard 00 to wizard n−1n - 1. If wizard i works on potion j, it takes skill[i] * mana[j] units of time.

Each wizard can work on at most one potion at a time, and each potion can be worked on by at most one wizard at a time. A potion must move from wizard i to wizard i + 1 immediately after wizard i finishes, meaning the start times must be chosen so that no potion ever waits between wizards.

Return the minimum possible time at which all m potions have finished brewing (after wizard n−1n - 1 completes the last potion).

Constraints:

  • n == skill.length

  • m == mana.length

  • 1≤‘n‘,‘m‘≤50001 \leq `n`, `m` \leq 5000

  • 1≤‘mana[i]‘,‘skill[i]‘≤50001 \leq `mana[i]`, `skill[i]` \leq 5000