Trains the technique from
LeetCode 2954Count the Number of Infection SequencesThis 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 nursery bench holds n saplings in one straight row, numbered 0 through n - 1. Two saplings are neighbours when their numbers differ by one.
The positions listed in sick, given in increasing order, already carry a blight. Every other sapling is healthy for now. Time passes in rounds, and in each round exactly one healthy sapling that has at least one blighted neighbour catches the blight. When several healthy saplings qualify in a round, any one of them may be the one that catches it. Rounds continue until nothing healthy is left.
A spread order is the list of positions of the initially healthy saplings, written in the order they caught the blight. Return how many different spread orders are possible, taken modulo 1000000007.
Example 1
Saplings 1, 2 and 3 start healthy. One possible spread order is [3, 2, 1]: sapling 3 touches the blighted sapling 4, then sapling 2 touches sapling 3, then sapling 1. Four spread orders are possible altogether.
Example 2
Saplings 0, 1, 4 and 5 start healthy. One possible spread order is [1, 4, 5, 0]. An order beginning with sapling 5 is not possible, because in the first round neither neighbour of sapling 5 carries the blight. Six spread orders are possible altogether.
Example 3
The blight sits in the middle of the bench with four healthy saplings on either side, and 70 spread orders are possible. One of them is [3, 5, 6, 2, 1, 7, 8, 0].
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 number_of_sequence(n: int, sick: list[int]) -> int:public int numberOfSequence(int n, int[] sick)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.