Linear Space and Linear time c++ solution


#1
vector<int> Solution::findPerm(const string A, int B) {
    int n=B;
    vector<int> v(n);
    v[0]=0;
    int next_big = 1;
    int next_small = -1;
    for(int i=1;i<n;i++)
    {
        if(A[i-1]=='I')
        {
            v[i]=next_big;
            next_big++;
        }
        else
        {
            v[i]=next_small;
            next_small--;
        }
    }
    ;
    for(int i=0;i<n;i++)
    {
        v[i]=v[i]-next_small;
    }
    return v;
}