O(n) Solution CPP Easy Concept


#1
vector<int> Solution::findPerm(const string arr, int B) {

int n = arr.length();
vector<int> ans(n+1);
int start = 1;
int end = B;

int i;
for(i=0; i<n;i++){
    if(arr[i] == 'I'){
        ans[i] = start++;
    }else{
        ans[i] = end--;
    }
}
ans[i] = start;
return ans;
}