Given an array arr,&nbsp;replace every element in that array with the greatest element among the elements to its&nbsp;right, and replace the last element with -1.

After doing so, return the array.

&nbsp;
Example 1:

Input: arr = [17,18,5,4,6,1]
Output: [18,6,6,6,1,-1]
Explanation: 
- index 0 --&gt; the greatest element to the right of index 0 is index 1 (18).
- index 1 --&gt; the greatest element to the right of index 1 is index 4 (6).
- index 2 --&gt; the greatest element to the right of index 2 is index 4 (6).
- index 3 --&gt; the greatest element to the right of index 3 is index 4 (6).
- index 4 --&gt; the greatest element to the right of index 4 is index 5 (1).
- index 5 --&gt; there are no elements to the right of index 5, so we put -1.


Example 2:

Input: arr = [400]
Output: [-1]
Explanation: There are no elements to the right of index 0.


&nbsp;
Constraints:


	1 &lt;= arr.length &lt;= 104
	1 &lt;= arr[i] &lt;= 105


class Solution:
    def replaceElements(self, arr: List[int]) -> List[int]:
        maxright = arr[-1]
        for i in range(len(arr) -1,-1,-1):
            temp = arr[i]
            arr[i] = maxright
            if temp > maxright:
                maxright = temp
        arr[-1] = -1
        
        return arr
class Solution {
    public int[] replaceElements(int[] arr) {
      int greatElement = -1;
        for(int i = arr.length-1; i >= 0; i--) {
            int temp = arr[i];
            arr[i] = greatElement;
            greatElement = Math.max(temp, greatElement);
        }
        return arr;
    }
}
class Solution {
public:
    vector<int> replaceElements(vector<int>& arr) {
        int n=arr.size();

        //taking last index as greatest for now
        int g=arr[n-1];
        //setting last index as -1
        arr[n-1]=-1;
        for(int i=n-2;i>=0;i--)
        {
        //storing last index value to be changed to comapare with the greatest value till now
            int h=arr[i];
            //assigning greatest till now from right
            arr[i]=g;
            //checking if current is greater than the previous indices
            if(h>g)
            {
                g=h;
            }
        }
                     //returning the value
     return arr;
    }
};
 * @param {number[]} arr
 * @return {number[]}
 */
var replaceElements = function(arr) {
    let max = arr[arr.length -1]
    
     for(let j=arr.length - 2; j>=0; --j){
         let curr = arr[j];
         arr[j] = max
         max = Math.max(max,curr)
     }
    
    arr[arr.length -1] = -1;
    return arr;
};
Replace Elements with Greatest Element on Right Side