Page cover

⭐Find Permutation

vector<int> Solution::findPerm(const string A, int B) {
    int n = A.size();
    vector<int> res(B);

    int ascending = 1;
    int descending = B;
    for(int i = 0; i < n; i++)
        if(A[i] == 'I')
            res[i] = ascending++;
        else
            res[i] = descending--;

    res[n] = (ascending + descending) / 2;

    return res;
}

Last updated