Successful Pairs of Spells and Potions
Real-world version: Dies That Hold Against Each PressThe statement here is our own: the same inputs, outputs and technique.
A workshop has presses with forces presses and dies with ratings dies. Pairing a press with a die makes a stamp whose strength is the two numbers multiplied, and the pairing holds when that strength is at least target.
Return a list whose entry i says how many of the dies hold when paired with press i.
Examples
Example 1
- Input
- presses = [2, 4, 6], dies = [5, 3, 1], target = 10
- Output
- [1, 2, 2]
The weakest press reaches the target only with the highest-rated die. Each of the other two presses manages it with two dies.
Example 2
- Input
- presses = [3], dies = [3], target = 9
- Output
- [1]
Three times three lands exactly on the target, and a pairing holds when it reaches the target rather than having to pass it.
Example 3
- Input
- presses = [1, 2, 3, 4, 5], dies = [1], target = 5
- Output
- [0, 0, 0, 0, 1]
The single die is rated 1, so a press holds only when its own force reaches the target.
Constraints
- 1 <= presses.length <= 10^5
- 1 <= dies.length <= 10^5
- 1 <= presses[i] <= 10^5
- 1 <= dies[i] <= 10^5
- 1 <= target <= 10^10
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def successful_pairs(presses: list[int], dies: list[int], target: int) -> list[int]:public int[] successfulPairs(int[] presses, int[] dies, long target)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Intersection of Two ArraysReal-world version: Shared Scan CodesEasy
- Earliest Finish Time for Land and Water Rides IReal-world version: Forge and Kiln BookingEasy
- Intersection of Two Arrays IIReal-world version: Shared Spare PartsEasy
- Check If N and Its Double ExistReal-world version: Twice Some Other EntryEasy