• + 0 comments

    C++ solution

    vector<int> permutationEquation(vector<int> p)
    {
        vector<int> o(p.size());
        int j,k=0;
        for (int i = 1; i <= p.size(); ++i)
        {
            while (p[j] != i && j < p.size()) {++j;};
            while (p[k] != j+1 && k < p.size()) {++k;};
            
            o.at(i-1) = k+1;
            
            j = 0;
            k = 0;
        }
        
        return o;
    }