Problem Brief
Minimum Possible Value of Function
OA
You are given an integer sequence X of length N, X=( X[1], X[2], ..., X[N]). The function F is defined as follows:
F(k)= |X[1] - (k + 1)| + |X[2] - (k + 2)| +...+|X[N]-(k+N)|
Where k is an integer.
What is the minimum possible value of F(k) among all possible integers k?
NOTE: Here |x| denotes the absolute value of x.
Function Description
Complete the function minimumPossibleValue in the editor.
minimumPossibleValue has the following parameter:
int[] X: an array of integers representing the sequence
Returns
long integer: the minimum possible value of F(k)
1Example 1
Input
X = [2, 2, 3, 5, 5]
Output
2
Explanation
F(0) = |1| + |0| + |0| + |1| + |0| = 2.
Constraints
Limits and guarantees your solution can rely on.
1 <= X[i] <= 10^91 <= N <= 2 * 10^5