Skip to main content
Back to problems
Leetcode
Medium
Arrays
Greedy
Sorting
Minimum Prefix Removal To Make Array Strictly Increasing

Remove the smallest possible prefix so the remaining array becomes strictly increasing.

Acceptance 0%
Problem Statement

Given an integer array, remove a prefix of length kk (possibly $0$ or the entire array) so that the remaining suffix is strictly increasing. Return the minimum possible prefix length.

A sequence is strictly increasing if every element is greater than the one before it.

The task is to find the earliest point where the array can be cut so that the suffix from that point onward is strictly increasing.

Input Format

  • An integer array nums.
  • You may remove a prefix nums[0..k-1] for some k in the range 0 <= k <= nums.length.
  • Return the minimum k such that nums[k..] is strictly increasing.

Output Format

  • Return one integer: the minimum prefix length to remove.

Constraints

  • 1 <= nums.length
  • Values may be negative or positive integers.
  • The remaining suffix may have length 0 or 1, which is always strictly increasing by definition.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1,2,3,2,4,5]

Output

3

Explanation

Removing the prefix [1,2,3] leaves [2,4,5], which is strictly increasing. No shorter prefix works.

Example 2

Input

nums = [5,4,3,2,1]

Output

4

Explanation

Removing the first 4 elements leaves [1], which is strictly increasing. Any shorter suffix has a decrease.

Show 1 more example

Example 3

Input

nums = [1,2,3]

Output

0

Explanation

The array is already strictly increasing, so no removal is needed.

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.