#K72607. Minimum Buildings Removal
Minimum Buildings Removal
Minimum Buildings Removal
You are given an array of integers representing the heights of a sequence of buildings. Your task is to remove the minimum number of buildings such that the heights of the remaining buildings form a strictly increasing sequence from left to right.
Formally, given an array \(H = [h_1, h_2, \dots, h_n]\), you need to determine the minimum number of removals so that the resulting sequence is strictly increasing. Equivalently, let \(LIS\) denote the longest strictly increasing subsequence of \(H\). You must compute and output: \[ n - |LIS|, \] where \(n\) is the total number of buildings.
Note: The remaining buildings must keep their original order.
inputFormat
The input is given in two lines:
- The first line contains an integer \(n\) denoting the number of buildings.
- The second line contains \(n\) space-separated integers, where the \(i\)th integer represents the height of the \(i\)th building.
outputFormat
Output a single integer --- the minimum number of buildings that need to be removed so that the heights of the remaining buildings form a strictly increasing sequence.
## sample7
4 2 3 6 10 5 7
3
</p>