#K88247. Minimum Skyline Operations
Minimum Skyline Operations
Minimum Skyline Operations
You are given a skyline represented by a sequence of building heights. In one operation, you can modify a contiguous segment of buildings (i.e. buildings that are adjacent) by setting all their heights to any desired uniform value. The objective is to make the entire skyline uniform (i.e. all buildings have the same height) with the fewest operations.
It can be observed that if the skyline is already divided into several contiguous segments of identical heights, then each segment can be changed with one operation. Hence, the answer is equal to the number of contiguous segments in the list.
Mathematically, if the input list is H = [H1, H2, ..., Hn], then the number of operations required is given by:
[ \text{operations} = 1 + \sum_{i=2}^{n} \mathbf{1}{{H_i \neq H{i-1}}} ]
Your task is to compute this number based on the provided list of building heights.
inputFormat
The input is given on two lines.
- The first line contains an integer
n
(1 ≤ n ≤ 105), which is the number of buildings. - The second line contains
n
space‐separated integers representing the heights of the buildings.
outputFormat
Output a single integer — the minimum number of operations required to make the skyline uniform.
## sample1
5
1
</p>