Skip to content

Practice Valid Permutations for DI Sequence

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

Hard#903
LeetCode Problem

Valid Permutations for DI Sequence

Problem Statement

For a string s of length n containing D and I, count permutations of all integers 0 through n that satisfy its comparisons. At position i, D requires perm[i] > perm[i + 1], while I requires perm[i] < perm[i + 1]. Return the count modulo 10^9 + 7.

Source: Valid Permutations for DI Sequence on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "DID"
Output
5

# Example 2

Input
s = "D"
Output
1

Constraints

n == s.length
1 <= n <= 200
s[i] is either 'I' or 'D'.

Related LeetCode Problems

Practice more problems similar to Valid Permutations for DI Sequence.

Review your practice with PhantomCodeAI

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