#C1638. Remove Shortest Subarray to Make Array Sorted

    ID: 44865 Type: Default 1000ms 256MiB

Remove Shortest Subarray to Make Array Sorted

Remove Shortest Subarray to Make Array Sorted

Given an array of n integers where \(1 \leq n \leq 10^5\), your task is to remove the shortest contiguous subarray such that the remaining array is sorted in non-decreasing order. In other words, find the minimum length of a contiguous subarray that can be removed so that the remaining elements, in their original order, form a non-decreasing sequence.

For instance, given the array [1, 2, 3, 10, 4, 2, 3, 5], if you remove the subarray [10, 4, 2], the remaining array becomes [1, 2, 3, 3, 5] which is sorted. Your job is to compute the minimum length of such a subarray.

inputFormat

The input is given through standard input (stdin) and has the following format:

  1. The first line contains an integer n representing the number of elements in the array.
  2. The second line contains n integers separated by spaces, representing the elements of the array.

outputFormat

Output a single integer to standard output (stdout) which represents the length of the shortest subarray that must be removed to make the remaining array sorted in non-decreasing order.

## sample
8
1 2 3 10 4 2 3 5
3

</p>