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 22, 2022
1 parent b8c42a3 commit e805cca
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 e805cca

Please sign in to comment.