Skip to content

Commit

Permalink
Create 1299-replace-elements-with-greatest-element-on-right-side.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Aasif853 authored Oct 30, 2023
1 parent ad0f0a4 commit 22c47cf
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def replace_elements(arr)
right_max = -1
(arr.length - 1).downto(0) do |i|
cur_max = [right_max, arr[i]].max
arr[i] = right_max
right_max = cur_max
end
arr
end

0 comments on commit 22c47cf

Please sign in to comment.