https://leetcode.com/discuss/interview-question/1781247/tusimple-oa-perfect-pairs
We have an array of n integers, point, and an integer, k. We can perform either of the following operations once for each point[i] in point:
Increment point[i] by k.
Decrement point[i] by k.
We want to perform an operation on each point[i] such that the difference between the maximum and minimum values in the array after performing all operations is minimal.
Complete the minimize function in the from the provided code. It has two parameters:
An array of n integers, point, where the value of each element corresponds to a point on the number line.
An integer, k, denoting the value that each element must either be incremented or decremented by.
The function must perform one operation on each pointi such that the absolute difference between the maximum and minimum values in the modified point array is minimal, then return an integer denoting the minimal difference between the modified array’s new maximum and minimum values.
Constraints
1 ≤ n ≤ 100
1 ≤ k ≤ 10^5
-10^5 ≤ point[i] ≤ 10^5
Output Format
The function must perform one operation on each pointi such that the absolute difference between the maximum and minimum values in the modified point array is minimal, then return an integer denoting this minimal difference between the array’s new maximum and minimum values. This is printed to stdout by the provided code.
Sample Input 0
3
-3
0
1
3
Sample Output 0
3
Explanation 0
We have point = [-3, 0, 1] and k = 3. If we add k to the first element and subtract it from the latter two elements, we get point = [-3 + 3, 0 − 3, 1 − 3] = [0, -3, -2]. We then take the absolute difference between the maximum and minimum values in point, which is |0 − -3| = 3, and return 3 as our answer.
3 questions, 1h:30 mins