Company: Walmart
Difficulty: medium
Minimum Possible Value You are given an integer sequence X of length N , written as X = (X[1], X[2], ..., X[N]) . For an integer k , the function F is defined as: F(k) = |X[1] - (k + 1)| + |X[2] - (k + 2)| + ... + |X[N] - (k + N)| In other words, F(k) measures how far X is from the arithmetic run k+1, k+2, ..., k+N , summed term by term. What is the minimum possible value of F(k) over all integers k ? Note that k may be any integer, including zero and negative integers. |x| denotes the absolute value of x . Function 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) Input format The first line contains a single integer N , the length of the sequence. The second line contains N space-separated integers X[1] X[2] ... X[N] . Output format Print a single integer: the minimum possible value of F(k) . Constraints 1 <= N