Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1251 from tharunkanna14/patch-3
Browse files Browse the repository at this point in the history
Create 1299_replace_elements_with_greatest_element_on_right_side.java
  • Loading branch information
Ahmad-A0 authored Nov 2, 2022
2 parents a35232f + 45d7093 commit 6c7d445
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 6c7d445

Please sign in to comment.