#K5011. Count Color Blocks
Count Color Blocks
Count Color Blocks
Given an array of integers, your task is to determine the number of distinct color blocks. A color block is defined as a maximal contiguous segment of the array where all elements are equal. For instance, if the array is given by \(a = [1, 2, 2, 3, 3, 3, 4]\), then there are 4 color blocks: [1], [2, 2], [3, 3, 3] and [4].
Formally, if the array is represented as \(a_1, a_2, \ldots, a_n\), then a new block is counted each time \(a_i \neq a_{i-1}\) for \(i \ge 2\). In the special scenario when \(n = 0\), the answer is defined as 0.
inputFormat
The input is provided via standard input (stdin). The first line contains a single integer (n) ((0 \le n \le 10^5)) which represents the number of elements in the array. The second line contains (n) space-separated integers, representing the array elements.
outputFormat
Output a single integer on standard output (stdout) denoting the number of distinct color blocks in the array.## sample
7
1 2 2 3 3 3 4
4