All problems
1122MediumArrayTwo PointersBinary SearchSorting

Dies That Hold Against Each Press

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2300Successful Pairs of Spells and Potions

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def successful_pairs(presses: list[int], dies: list[int], target: int) -> list[int]:
Java
public int[] successfulPairs(int[] presses, int[] dies, long target)
September 7
Apply