Skip to content

Practice DI String Match

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

Easy#942
LeetCode Problem

DI String Match

Problem Statement

For a string s of length n, return any permutation of 0 through n. Each I at position i requires perm[i] < perm[i + 1], and each D requires perm[i] > perm[i + 1]. Use each integer exactly once.

Source: DI String Match on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "IDID"
Output
[0,4,1,3,2]

# Example 2

Input
s = "III"
Output
[0,1,2,3]

# Example 3

Input
s = "DDI"
Output
[3,2,0,1]

Constraints

1 <= s.length <= 10^5
s[i] is either 'I' or 'D'.

Related LeetCode Problems

Practice more problems similar to DI String Match.

Review your practice with PhantomCodeAI

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