Skip to content

Commit

Permalink
Merge pull request #3105 from Aasif853/Aasif-tecno-patch-1
Browse files Browse the repository at this point in the history
Create 1299-replace-elements-with-greatest-element-on-right-side.rb
  • Loading branch information
Ykhan799 authored Nov 10, 2024
2 parents d68871c + 22c47cf commit 7f17417
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 7f17417

Please sign in to comment.