Leetcode 1551. Minimum Operations to Make Array Equal
Given n and the array arr[i]=2*i+1, compute the minimum number of unit transfers (subtract 1 from one element and add 1 to another) required to make all elements equal — equivalently the sum of absolute deviations to the median divided by 2. This has a closed form: answer = floor(n/2) * ceil(n/2) (i.e., n^2/4 for even n and (n^2-1)/4 for odd n).
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.