Skip to content

Practice Count the Number of Infection Sequences

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2954
LeetCode Problem

Count the Number of Infection Sequences

Problem Statement

You are given an integer n and an array sick sorted in increasing order, representing positions of infected people in a line of n people. At each step, one uninfected person adjacent to an infected person gets infected. This process continues until everyone is infected. An infection sequence is the order in which uninfected people become infected, excluding those initially infected. Return the number of different infection sequences possible, modulo 10^9+7.

Source: Count the Number of Infection Sequences on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5, sick = [0,4]
Output
4

# Example 2

Input
n = 4, sick = [1]
Output
3

Constraints

2 <= n <= 10^5
1 <= sick.length <= n - 1
0 <= sick[i] <= n - 1
sick is sorted in increasing order.

Related LeetCode Problems

Practice more problems similar to Count the Number of Infection Sequences.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.