484. Find Permutation

You are given a string s of length n, where each character is either 'I' (increasing) or 'D' (decreasing). You need to reconstruct a permutation p of numbers [1, 2, ..., n+1] that satisfies the following rule:

  • If s[i] == 'I', then p[i] < p[i+1]
  • If s[i] == 'D', then p[i] > p[i+1]

Return the lexicographically smallest (smallest in dictionary order) such permutation.

Examples
Input: "I"
Output: [1,2]
Hints
Related Problems

484. Find Permutation

You are given a string `s` of length `n`, where each character is either 'I' (increasing) or 'D' (decreasing). You need to reconstruct a permutation `p` of numbers `[1, 2, ..., n+1]` that satisfies the following rule: