If it's all just `I`

, then the answer is the numbers in ascending order. And if there are streaks of `D`

, then just reverse the number streak under each:

My 5-liner does exactly that. Start from sorted, then find the `D`

-streaks and reverse the numbers under them:

```
def findPermutation(self, s):
a = range(1, len(s) + 2)
for m in re.finditer('D+', s):
i, j = m.start(), m.end() + 1
a[i:j] = a[i:j][::-1]
return a
```

My 1-liner tells `sorted`

that the (larger) number `i`

comes before the (smaller) number `j`

iff they're both under the same `D`

-streak, i.e., iff there's no `I`

between them. (I'm not totally sure that `i`

will always be the larger number, but it appears to be the case).

```
def findPermutation(self, s):
return sorted(range(1, len(s) + 2), cmp=lambda i, j: -('I' not in s[j-1:i-1]))
```