package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/
 */
public class Problem1299 {
    public int[] replaceElements(int[] arr) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1299 prob = new Problem1299();
        System.out.println(Arrays.toString(prob.replaceElements(new int[]{17, 18, 5, 4, 6, 1}))); // [18,6,6,6,1,-1]
    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -192,251 +192,274 @@
     
-// TODO%0A        return null
+int%5B%5D answer = new int%5Barr.length%5D;%0A        answer%5Barr.length - 1%5D = -1
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1299 prob = new Problem1299();%0A        System.out.println(Arrays.toString(prob.replaceElements(new int%5B%5D%7B17, 18, 5, 4, 6, 1%7D))); // %5B18,6,6,6,1,-1%5D
+int max = arr%5Barr.length - 1%5D;%0A        for (int i = arr.length - 2; i %3E= 0; i--) %7B%0A            answer%5Bi%5D = max;%0A            max = Math.max(max, arr%5Bi%5D);%0A        %7D%0A        return answer;
 %0A   

Solve problem 1299