Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

replace elements with greatest element on right side

public class Solution 
{
    public int[] ReplaceElements(int[] arr)
    {
        int rightMax=-1;
        for(int i=arr.Length-1;i>=0;i--)
        {
           	int newMax=Math.Max(rightMax,arr[i]);
            arr[i]=rightMax;
            rightMax=newMax;
        }
        return arr;
    }
}
 
PREVIOUS NEXT
Tagged: #replace #elements #greatest #element #side
ADD COMMENT
Topic
Name
4+1 =