Minimum Deletions To Make Sorted Array

easy
1. You are given a number N representing number of elements.
2. You are given N space separated numbers representing (ELE)elements.
3. Find the minimum number of deletions/removals needed such that remaining elements are (strictly)sorted.

Input Format

A number N(number of elements) ELE1 ,ELE2 ,ELE3 ,ELE4 ,ELE5 .... ELEn (N space separated elements)

Output Format

Find the minimum number of deletions/removals. Check the sample output and question video.

Constraints

1 <= N <= 100000
1 <= Elei <= 50000

Example

Input
10
40 10 55 18 14 41 61 62 25 50 
Output
5
Previous
Minimal Platforms
Next
Minimum Deletions To Make Palindromic Sequence

Related Questions