Skip to content

Commit 046cb93

Browse files
authored
Merge pull request neetcode-gh#1215 from BlacKnight-RH/feature/ts-solution-for-1299-Replace-Elements-with-Greatest-Element-on-Right-Side
[ADD] Add ts solution for 1299-Replace-Elements-with-Greatest-Element…
2 parents 3a38054 + b40a630 commit 046cb93

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+
function replaceElements(arr: number[]): number[] {
2+
let currMax = -1;
3+
4+
for(let i = arr.length -1 ; i >= 0; i--) {
5+
let newMax = Math.max(currMax, arr[i]);
6+
arr[i] = currMax;
7+
8+
currMax = newMax;
9+
}
10+
11+
return arr;
12+
};

0 commit comments

Comments
 (0)