1299. Replace Elements with Greatest Element on Right Side

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1299

class Solution:
    def replaceElements(self, arr: List[int]) -> List[int]:
        m = -1
        for i in range(len(arr) - 1, -1, -1):
            t = arr[i]
            arr[i] = m
            m = max(m, t)
        return arr