less than 1 minute read

Given a list of integers nums, replace every nums[i] with the smallest integer left of i. Replace nums[0] with 0.

Constraints

  • 1 ≤ n ≤ 100,000 where n is the length of nums

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

Examples

Example 1

Input

  • nums = [10, 5, 7, 9]

Output

  • answer = [0, 10, 5, 5]

Explanation

  • nums[0] = 0 by definition
  • nums[1] = min(10)
  • nums[2] = min(5, 10)
  • nums[3] = min(7, 5, 10)

Solution

Leave a comment