Tap here to switch tabs
Problem
Submissions

Problem: Find Permutation

med
30 min
Try to solve the Find Permutation problem.

Statement

A secret permutation of integers from 11 to n+1n + 1 is encoded as a string s of length nn, where for each index i:

  • s[i] == 'I' indicates that the permutation satisfies perm[i] < perm[i + 1] (increasing).

  • s[i] == 'D' indicates that the permutation satisfies perm[i] > perm[i + 1] (decreasing).

Given the encoded string s, reconstruct and return the lexicographically smallest valid permutation.

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: Find Permutation

med
30 min
Try to solve the Find Permutation problem.

Statement

A secret permutation of integers from 11 to n+1n + 1 is encoded as a string s of length nn, where for each index i:

  • s[i] == 'I' indicates that the permutation satisfies perm[i] < perm[i + 1] (increasing).

  • s[i] == 'D' indicates that the permutation satisfies perm[i] > perm[i + 1] (decreasing).

Given the encoded string s, reconstruct and return the lexicographically smallest valid permutation.

Constraints:

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

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