Skip to content

Commit 1c09df7

Browse files
authored
Create 1299-replace-elements-with-greatest-element-on-right-side.js
1 parent 2249138 commit 1c09df7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {number[]} arr
3+
* @return {number[]}
4+
*/
5+
const replaceElements = function(arr) {
6+
const suffix = [-1], n = arr.length
7+
for(let i = n - 2; i >= 0; i--) {
8+
suffix.unshift(Math.max(suffix[0], arr[i + 1]))
9+
}
10+
11+
return suffix
12+
};

0 commit comments

Comments
 (0)