@@ -0,0 +1,631 @@
+package com.coderevisited.coding;%0A%0Apublic class ReplaceWithNextGreatest%0A%7B%0A    public static void main(String%5B%5D args)%0A    %7B%0A        int%5B%5D array = new int%5B%5D%7B16, 6, 9, 10, 11, 17, 4, 3, 9, 8, 5, 2, 14%7D;%0A        replaceWithNextGreatest(array);%0A%0A        for (int i : array) %7B%0A            System.out.print(i + %22 %22);%0A        %7D%0A        System.out.println();%0A    %7D%0A%0A    private static void replaceWithNextGreatest(int%5B%5D array)%0A    %7B%0A        int max = -1;%0A        for (int i = array.length - 1; i %3E= 0; i--) %7B%0A            int current = array%5Bi%5D;%0A            array%5Bi%5D = max;%0A            max = max %3E current ? max : current;%0A        %7D%0A    %7D%0A%7D%0A

Replace With next greatest element