Skip to content

Commit

Permalink
Create 1299_replace_elements_with_greatest_element_on_right_side.java
Browse files Browse the repository at this point in the history
  • Loading branch information
tharunkanna14 authored Oct 10, 2022
1 parent 71d4c5c commit b8c42a3
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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;
}
}

0 comments on commit b8c42a3

Please sign in to comment.