Data Reorganization
Learn this problemProblem statement
While analyzing data, you are working with an array data containing n positive integers, each representing a dataset values.
To derive new features for data analysis, you can perform the following operations:
(i,j) (0-based) such that 0 ≤ i < j < len(data).|data[i] - data[j]|.data, increasing its length by 1.
The objective is to minimize the smallest value present in data after performing exactly maxOperations operations.
Write a program to compute the minimum possible value of the smallest element in data after the given operations.
Function
getMinimumValue(data: int[], maxOperations: int) → int
Complete the function getMinimumValue in the editor with the following parameters:
int data[]: the datasetint maxOperations: the number of operations to be performed
Returns
int: the smallest possible value of the minimum element in data after exactly maxOperations operations.
Constraints
2 ≤ n ≤ 2*10^31 ≤ data[i] ≤ 10^91 ≤ maxOperations ≤ 10^9
🍻 Many, many thanks to one of our dearest and very best friends for being with FastPrep every step of the way! (Oct 17, 2025 :) 🧡
Examples
Example 1
data = [42, 47, 50, 54, 62, 79]maxOperations = 2return = 3The underlined values are selected for each operation. One optimal sequence is:
| Operation Number | data[] before | data[] after |
|---|---|---|
| 1 | [42, 47, 50, 54, 62, 79] | [42, 47, 50, 54, 62, 79, 15] |
| 2 | [42, 47, 50, 54, 62, 79, 15] | [42, 47, 50, 54, 62, 79, 15, 3] |
The first operation appends |47 - 62| = 15. The second appends |47 - 50| = 3. The smallest possible value of the minimum element is 3.
Example 2
data = [4, 2, 5, 9, 3]maxOperations = 1return = 1The underlined values are selected for the operation. One optimal operation is:
| Operation Number | data[] before | data[] after |
|---|---|---|
| 1 | [4, 2, 5, 9, 3] | [4, 2, 5, 9, 3, 1] |
The operation appends |4 - 3| = 1. The smallest possible value of the minimum element is 1.
Example 3
data = [5, 18, 3, 12, 11]maxOperations = 2return = 1Constraints
See the very last portion of the problem statement above 👆