Javascript, easy to understand
Noted that this array is an arithmetic sequence. To make the elements equal to the same number, it has to be the one in the "middle". And other values on each s
Noted that this array is an arithmetic sequence. To make the elements equal to the same number, it has to be the one in the "middle". And other values on each side just increment and decrement accordingly. This will result into minimum number of operations.\n\nAlso remember the formula for sum of arithmetic sequences: `sum = N * (A1 + An) / 2`, with `n` being the number of the elements in the sequence, `A1` the first element, `An` the last element.\n\n```js\nvar minOperations = function(n) {\n    // For example when n = 4\n    // 1 3 5 7    -> (4 is the middle element)\n    // 3 1 ..     -> (steps to increment to become the middle element\n    if (n % 2 === 0) {\n        // return (n / 2) * (1 + n - 1) / 2; (N = n/2 , A1 = 1 and An = n - 1)\n        return n * n / 4; // simplified above\n    }\n    // For example when n = 5\n    // 1 3 5 7 9  -> (5 is the middle element)\n    // 4 2        -> (steps to increment to become the middle element)\n    // return (n - 1) / 2 * (2 + n - 1) / 2; (N = (n-1)/2 , A1 = 2 and An = n - 1)\n    return (n * n - 1) / 4;\n\t\n\t// Also you can combine above two cases.\n\t// return (n * n - n % 2) / 4;\n};\n```
['JavaScript']