Minimum Possible Value of Function

Walmart interviews coding interview problem: Given an integer sequence X, define F(k) as the sum of |X[i] − (k + i)| for i=1..N. Find the minimum possible value of F(k) over all integer k. This interview question focuses on evaluating a function over a shifted index and returning the minimal sum as a long integer.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: