Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

DI String Match

XPChallenge Points: 10
levelLevel: Easy

You are given a string s made of characters 'I' and 'D'.

  • 'I' means the next number should be greater than the current number.

  • 'D' means the next number should be smaller than the current number.

You need to create a permutation (an ordering) of numbers from 0 to n (where n is the length of s) which follows this rule throughout the string.
If multiple such permutations are possible, you may return any one of them.

Example 1:

Input: s = "IIID"

Output: [0,1,2,3,1]

Explanation:

First 3 positions increase, last decreases.

Example 2:

Input: s = "DID"

Output: [3,1,2,0]

Explanation:

D → 3 > 1 I → 1 < 2 D → 2 > 0

Example 3:

Input: s = "DDDD"

Output: [4,3,2,1,0]

Explanation:

Each step must decrease.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result