Java Sol. Stack based


#1
public class Solution {
    // DO NOT MODIFY THE LIST. IT IS READ ONLY
    public ArrayList<Integer> findPerm(final String A, int n){
        Stack<Integer> st = new Stack<>();
        ArrayList<Integer> al = new ArrayList<>();
        int j = 1;
        for(int i=0; i<=n-1; i++){
            st.push(j++);
            if(i==n-1 || A.charAt(i)=='I'){
                while(!st.isEmpty()){
                    al.add(st.pop());
                }
            }
        }
        return al;
    }
}