Leetcode 1231 Solution
This article provides solution to leetcode question 1231 (replace-elements-with-greatest-element-on-right-side)
Access this page by simply typing in "lcs 1231" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side
Solution
class Solution:
def replaceElements(self, arr: List[int]) -> List[int]:
ans = [-1] * len(arr)
i = len(arr) - 1
curr = -1
while i >= 0:
ans[i] = curr
curr = max(curr, arr[i])
i -= 1
return ans