0903. Valid Permutations for DI Sequence
https://leetcode.com/problems/valid-permutations-for-di-sequence
Description
You are given a string s
of length n
where s[i]
is either:
'D'
means decreasing, or'I'
means increasing.
A permutation perm
of n + 1
integers of all the integers in the range [0, n]
is called a valid permutation if for all valid i
:
If
s[i] == 'D'
, thenperm[i] > perm[i + 1]
, andIf
s[i] == 'I'
, thenperm[i] < perm[i + 1]
.
Return the number of valid permutations perm
. Since the answer may be large, return it modulo 109 + 7
.
Example 1:
Example 2:
Constraints:
n == s.length
1 <= n <= 200
s[i]
is either'I'
or'D'
.
ac
Last updated