function to find minimum required permutation
def StringMatch ( S ) : NEW_LINE INDENT lo , hi = 0 , len ( S ) NEW_LINE ans = [ ] NEW_LINE for x in S : NEW_LINE INDENT if x == ' I ' : NEW_LINE INDENT ans . append ( lo ) NEW_LINE lo += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans . append ( hi ) NEW_LINE hi -= 1 NEW_LINE DEDENT DEDENT return ans + [ lo ] NEW_LINE DEDENT