FastPrepFastPrep
Problem Brief

Find Minimum Machines Size

FULLTIMEOA
See Amazon online assessment and hiring insights

An analyst in the logistics team of Amazon e-commerce was reviewing the efficiency metrics of the new automated stocking and retrieval machines. They went about their calculations in the following manner:

A sequence of n machines is tasked with stocking or retrieving items. Given the individual stocking/retrieving capacity values of each machine as an integer array, machineCapacity.

The Efficiency of this sequence is evaluated using a comparison metric: the sum of the absolute difference between consecutive machine capacities.

The task is to determine whether achieving the same sum of the absolute difference is possible by removing some machines from the sequence to streamline the operations. If it is possible, return the minimum number of machines required in the sequence to attain the same sum of the absolute difference between consecutive machine capacities.

It's important to note that the number of machines in the sequence must always be greater than 0. If achieving the same sum is impossible on removal, return n, which is the original number of machines in the sequence.

Note: The efficiency score of a sequence consisting of only one machine is 0.

Function Description

findMinimumMachinesSize() has the following parameter(s):

  • int machineCapacity[n]: the stocking/retrieval capacity of each machine

Returns

int: the minimum number of machines in the sequence required to achieve the same performance score

Following is very likely a duplicate of this problem -

Reasons for being duplicate -

After comparing both problems, we are leaning toward (Find Minimum Machines Size) as the correct version. It seems likely that Minimize Array Differences was from memory, while Find Minimum Machines Size might’ve been copied more directly — which tends to be more reliable. Also, returning the number of operations (as in Find Minimum Machines Size) feels more aligned with what we typically see in these types of problems. And with the potential error in Example 2 of Minimize Array Differences that a pro pointed out, it just adds to the uncertainty around that version.

1Example 1

Input
machineCapacity = [1, 2, 2, 1, 1]
Output
3
Explanation
Efficiency initially: ∣1−2∣ + ∣2−2∣ + ∣2−1∣ + ∣1−1∣ = 2 Efficiency after removal of position [2],[3]: ∣1−2∣ + ∣2−1∣ = 2 It can be seen that after the removal of these 2 machines, we obtain the same efficiency. Thus, the answer in this case is 3. It can be proven that the answer can't be less than 3.

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≤ n ≤ 2*10^5
  • 0 ≤ machineCapacity[i] ≤ 10^9
public int findMinimumMachinesSize(int[] machineCapacity) {
  // write your code here
}
Input

machineCapacity

[1, 2, 2, 1, 1]

Output

3

Sign in to submit your solution.