Description
Solutions
Submission
Minimum Possible Value of Function

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:

  1. int[] X: an array of integers representing the sequence

Returns

long integer: the minimum possible value of F(k)

Example 1:

Input:  X = [2, 2, 3, 5, 5]
Output: 2
Explanation:
F(0) = |1| + |0| + |0| + |1| + |0| = 2.
Constraints:
    • 1 <= X[i] <= 10^9
    • 1 <= N <= 2 * 10^5
Thumbnail 0
Testcase

Result
Case 1

input:

output: