Problem statement

https://binarysearch.com/problems/List-Min-Replacement/

Solution

We need to keep cumulative min of prefixes.

Complexity

It is O(n) for time and O(1) for space.

Code

class Solution:
    def solve(self, x):
        x[0], mn = 0, x[0]
        for i in range(1, len(x)):
            x[i], mn = mn, min(x[i], mn)
        return x