FastPrepFastPrep
Problem Brief

Data Reorganization

OA

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:

  • 1. Select a pair of indices (i,j) (0-based) such that 0 ≤ i < j < len(data).
  • 2. Compute the absolute difference |data[i] - data[j]|.
  • 3. Append this value to the end of the array 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 Description

    Complete the function getMinimumValue in the editor with the following parameters:

    • int data[]: the dataset
    • int 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^3
    • 1 ≤ data[i] ≤ 10^9
    • 1 ≤ maxOperations ≤ 10^9

    🍻 Many, many thanks to one of our dearest and very best friends for being with FastPrep every step of the way! 🧡

    1Example 1

    Input
    data = [42, 47, 50, 54, 62, 79], maxOperations = 2
    Output
    3
    Explanation
    Example 1 illustration
    The underlined values are selected for the operation. An optimal sequence of operation is as follows: The smallest possible value of the minimum element is 3.

    2Example 2

    Input
    data = [4, 2, 5, 9, 3], maxOperations = 1
    Output
    1
    Explanation
    Example 2 illustration
    The underlined values are selected for the operation. An optimal sequence of operation is as follows: The smallest possible value of the minimum element is 1.

    3Example 3

    Input
    data = [5, 18, 3, 12, 11], maxOperations = 2
    Output
    1
    Explanation
    The smallest possible value of the minimum element is 1 :)

    Constraints

    Limits and guarantees your solution can rely on.

    See the very last portion of the problem statement above 👆
    public int getMinimumValue(int[] data, int maxOperations) {
      // write your code here
    }
    
    Input

    data

    [42, 47, 50, 54, 62, 79]

    maxOperations

    2

    Output

    3

    Sign in to submit your solution.