Tap here to switch tabs
Problem
Submissions

Problem: DI String Match

med
30 min
Try to solve the DI String Match problem.

Statement

A permutation perm of n+1n + 1 integers in the range [0,n][0, n] can be represented as a string s of length nn such that for all 0≤i<n0 \leq i < n:

  • perm[i] < perm[i + 1] if s[i] == 'I'

  • perm[i] > perm[i + 1] if s[i] == 'D'

Given a string s, reconstruct and return any valid permutation perm. If there are multiple valid permutations, return any of them.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: DI String Match

med
30 min
Try to solve the DI String Match problem.

Statement

A permutation perm of n+1n + 1 integers in the range [0,n][0, n] can be represented as a string s of length nn such that for all 0≤i<n0 \leq i < n:

  • perm[i] < perm[i + 1] if s[i] == 'I'

  • perm[i] > perm[i + 1] if s[i] == 'D'

Given a string s, reconstruct and return any valid permutation perm. If there are multiple valid permutations, return any of them.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

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