Replace Elements with Greatest Element on Right Side- TLE

Some sample test cases are running but facing TLE while submitting. Can somebody explain?

class Solution {
public:
vector replaceElements(vector& arr) {

    int n=arr.size();
    
    
    for(int i=0;i<n;i++)
    {
        int max=0;
        vector<int> vect={0};
        for(int j=i+1;j<n;j++)
        {
            vect.push_back(arr[j]);
        }
        
        max=*max_element(vect.begin(),vect.end());
        arr[i]=max;
    }
    arr[n-1]=-1;
    
    return arr;
    
}

};

Comments (1)