Fastest and simplest C++:


#1

vector Solution::findPerm(const string A, int B) {
vector v;
int maxTill = B;
int minTill = 1;
for(int i=0;i<A.size();i++){
if(A[i]==‘I’){
v.push_back(minTill);
minTill++;
}else{
v.push_back(maxTill);
maxTill–;
}
}
if(A[A.size()-1]==‘I’) v.push_back(maxTill);
else v.push_back(minTill);
return v;
}