Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Infection Sequences

med
30 min
Try to solve the Count the Number of Infection Sequences problem.

Statement

You are given an integer n and a 00 indexed integer array sick sorted in increasing order.

There are n individuals standing in a row, indexed from 00 to n −1- 1. The array sick contains the indices of the individuals who are initially infected. In each step, an uninfected individual can become infected if they are adjacent to at least one infected individual. The process continues until every individual is infected.

An infection sequence is the ordered list of indices of individuals as they become infected.

Return the total number of distinct possible infection sequences. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • 2≤2 \leq n ≤105\leq 10^5

  • 1≤1 \leq sick.length ≤\leq n −1- 1

  • 0≤0 \leq sick[i] ≤\leq n −1- 1

  • sick is sorted in increasing order.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Infection Sequences

med
30 min
Try to solve the Count the Number of Infection Sequences problem.

Statement

You are given an integer n and a 00 indexed integer array sick sorted in increasing order.

There are n individuals standing in a row, indexed from 00 to n −1- 1. The array sick contains the indices of the individuals who are initially infected. In each step, an uninfected individual can become infected if they are adjacent to at least one infected individual. The process continues until every individual is infected.

An infection sequence is the ordered list of indices of individuals as they become infected.

Return the total number of distinct possible infection sequences. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • 2≤2 \leq n ≤105\leq 10^5

  • 1≤1 \leq sick.length ≤\leq n −1- 1

  • 0≤0 \leq sick[i] ≤\leq n −1- 1

  • sick is sorted in increasing order.