Replace Elements with Greatest Element on Right Side
Input: arr = [17,18,5,4,6,1]
Output: [18,6,6,6,1,-1]class Solution:
def replaceElements(self, arr: List[int]) -> List[int]:
A = arr
mx = -1
for i in range(len(A) - 1, -1, -1):
A[i], mx = mx, max(mx, A[i])
return ALast updated