Tap here to switch tabs
Problem
Submissions

Problem: Count Number of Special Subsequences

med
30 min
Try to solve the Count Number of Special Subsequences problem.

Statement

A sequence is defined as special if it contains at least one 00, followed by at least one 11, followed by at least one 22.

Given an integer array nums, return the number of distinct special subsequences modulo 109+710^9 + 7.

Note: A subsequence is formed by deleting zero or more elements from an array without altering the relative order of the remaining elements. Two subsequences are considered distinct if they are formed using different sets of indices.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤2\leq 2

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Number of Special Subsequences

med
30 min
Try to solve the Count Number of Special Subsequences problem.

Statement

A sequence is defined as special if it contains at least one 00, followed by at least one 11, followed by at least one 22.

Given an integer array nums, return the number of distinct special subsequences modulo 109+710^9 + 7.

Note: A subsequence is formed by deleting zero or more elements from an array without altering the relative order of the remaining elements. Two subsequences are considered distinct if they are formed using different sets of indices.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤2\leq 2