Tap here to switch tabs
Problem
Submissions

Problem: Valid Permutations for DI Sequence

med
30 min
Try to solve the Valid Permutations for DI Sequence problem.

Statement

You are given a string s of length n, where s[i] is either 'I' representing an increase or 'D' representing a decrease.

A permutation perm of the integers in the range [0,n][0, n] is considered valid if for all 0≤i<n0 \leq i < n:

  • If s[i] == 'I', then perm[i] < perm[i + 1]

  • If s[i] == 'D', then perm[i] > perm[i + 1]

Return the total number of valid permutations perm. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • n == s.length

  • 1≤n≤2001 \leq n \leq 200

  • s[i] is either 'I' or 'D'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Valid Permutations for DI Sequence

med
30 min
Try to solve the Valid Permutations for DI Sequence problem.

Statement

You are given a string s of length n, where s[i] is either 'I' representing an increase or 'D' representing a decrease.

A permutation perm of the integers in the range [0,n][0, n] is considered valid if for all 0≤i<n0 \leq i < n:

  • If s[i] == 'I', then perm[i] < perm[i + 1]

  • If s[i] == 'D', then perm[i] > perm[i + 1]

Return the total number of valid permutations perm. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • n == s.length

  • 1≤n≤2001 \leq n \leq 200

  • s[i] is either 'I' or 'D'