Trains the technique from
LeetCode 3850Count Sequences to KThis 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 run of dice throws is given as nums, each a number from 1 to 6.
A selection takes some of the throws, keeping their order, and its score is the product of the throws taken. Two selections are different when they take different positions, even if the throws taken read the same.
Return how many non-empty selections score exactly k.
Example 1
Selections scoring 24 include the throws 4 and 6, the throws 2, 3 and 4, and each of those again with the throw of 1 taken as well, since taking it changes nothing about the product but does make a different selection.
Example 2
Any non-empty selection of throws of one scores one, and there are seven of them.
Example 3
The only selection scores 6, so nothing scores 5.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def count_sequences(nums: list[int], k: int) -> int:public int countSequences(int[] nums, long k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.