Cumulative Minimum

EasyData EngineeringArrayPrefix Sum

Description

Given an array of numbers, return an array where each position holds the minimum of all values from the start up to and including that position.

Examples

Input:[3,1,4,1,5]
Output:[3,1,1,1,1]
Explanation:

Each position carries the smallest value seen so far while scanning from the start of the array.

Input:[5,4,3]
Output:[5,4,3]
Explanation:

Each position carries the smallest value seen so far while scanning from the start of the array.

Input:[1,2,3]
Output:[1,1,1]
Explanation:

Each position carries the smallest value seen so far while scanning from the start of the array.

Constraints

  • 1 ≤ length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.