#C4656. Minimum Operations to Form Arithmetic Sequence
Minimum Operations to Form Arithmetic Sequence
Minimum Operations to Form Arithmetic Sequence
You are given an array of n integers. In one operation, you can change a single element to any integer value. Your task is to determine the minimum number of such operations required to transform the array into an arithmetic sequence.
An arithmetic sequence is one in which the difference between consecutive elements is constant. In other words, an array a is an arithmetic sequence if and only if for some integer \(d\) (the common difference) and for all \(i\) (1-based index), \[ a_i = a_1 + (i-1) \times d, \] with \(1 \le i \le n\). Note that when \(n \le 2\), the array is trivially an arithmetic sequence.
Input Example: For instance, the array [2, 4, 6, 8, 12] can be transformed into an arithmetic sequence [2, 4, 6, 8, 10] with only 1 operation.
Your program should read an integer \(n\) (the number of elements) followed by \(n\) space-separated integers. It should output the minimum number of operations needed.
inputFormat
The first line contains an integer n representing the number of elements in the array.
The second line contains n space-separated integers.
outputFormat
Output a single integer representing the minimum number of operations required to transform the array into an arithmetic sequence.
## sample5
1 3 5 7 9
0
</p>