Python Solution | O(n) time | O(n) space


#1
class Solution:
    # @param A : string
    # @param B : integer
    # @return a list of integers
    def findPerm(self, s, n):
        res=[]
        inc=1
        dec=n
        for i in s:
            if i=='I':
                res+=[inc]
                inc+=1
            else:
                res+=[dec]
                dec-=1
        res+=[inc if s[-1]=='I' else dec]
        return res