Easy java solution O(n) with no space


#1
public ArrayList<Integer> findPerm(final String A, int B) {
    int low = 1, high = B;
    ArrayList<Integer> out = new ArrayList<Integer>();
    
    for (int i = 0; i < B - 1; i++){
        char c = A.charAt(i);
        
        if (c == 'D'){
            out.add(high);
            high--;
        }
        if (c == 'I'){
            out.add(low);
            low++;
        }
    }
    
    out.add(low);
    
    return out;
}

#2

wow! That is so simple! Great solution :clap:


#3

Sir, will it work for IDDI ->> 1 4 3 2 5


#4

this won’t work for IDID