Skip to content

Commit bd766d7

Browse files
Create 1299_replace_elements_with_greatest_element_on_right_side.go
1 parent fd465a1 commit bd766d7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func findMaxElement(rightMax int, lastElement int) int {
2+
if lastElement > rightMax {
3+
rightMax = lastElement
4+
}
5+
return rightMax
6+
}
7+
8+
func replaceElements(arr []int) []int {
9+
var rightMax int = -1
10+
for i := len(arr) - 1; i >= 0; i-- {
11+
var newMax int = findMaxElement(rightMax, arr[i])
12+
arr[i] = rightMax
13+
rightMax = newMax
14+
}
15+
return arr
16+
}

0 commit comments

Comments
 (0)