Skip to main content
Back to problems
Leetcode
Medium
Arrays
Sorting
Greedy
Make Array Non Decreasing

Modify an array using the allowed operation(s) so that the final sequence becomes non-decreasing.

Acceptance 0%
Problem Statement

Problem

Given an integer array, apply the allowed operation(s) defined by the problem so that the array becomes non-decreasing (that is, each element is at least the previous one).

Your goal is to determine the required result for the array after performing the process described in the statement, or to decide whether it is possible depending on the exact operation rules.

A sequence is non-decreasing if for every index i>0i > 0, we have:

a[i]≥a[i−1]a[i] \ge a[i-1]

Work with the array in order and reason about how earlier values constrain later ones.

Input Format

  • An integer nn describing the size of the array.
  • An array of nn integers.
  • Any additional operation parameters if applicable to the variant.

Output Format

  • Return the transformed array, or
  • return the minimum number of operations / a feasibility result, depending on the exact variant.

Constraints

  • The array size is positive.
  • Values may be negative or positive integers.
  • The final array must satisfy a[i]≥a[i−1]a[i] \ge a[i-1] for all valid ii.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [5, 4, 3, 2]

Output

[5, 5, 5, 5]

Explanation

Illustrative example: after enforcing a non-decreasing sequence, later values may need to be raised to match earlier constraints.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.