Find Minimum Machines Size
Learn this problemProblem statement
A sequence of n machines is tasked with stocking or retrieving items. You are given the individual stocking/retrieving capacity values of each machine as an integer array, machineCapacity.
The Efficiency of a sequence is defined as the sum of the absolute differences between consecutive machine capacities. For a sequence a of length k, the efficiency is |a[0]-a[1]| + |a[1]-a[2]| + ... + |a[k-2]-a[k-1]|. The efficiency of a sequence consisting of a single machine is 0.
Your task is to remove zero or more machines from the sequence so that the remaining sequence has the same efficiency as the original sequence. When machines are removed, the relative order of the remaining machines must be preserved (the result must be a subsequence of the original array, not a reordering).
Among all subsequences whose efficiency equals the original efficiency, return the minimum possible number of machines (the smallest subsequence length). The remaining sequence must contain at least one machine. If the original array already has all equal elements (efficiency 0), the minimum is 1, since a single machine also has efficiency 0.
If it is impossible to remove any machine while preserving the original efficiency, return n, the original number of machines.
Function
findMinimumMachinesSize(machineCapacity: int[]) → intfindMinimumMachinesSize() has the following parameter(s):
int machineCapacity[n]: the stocking/retrieval capacity of each machine
Returns
int: the minimum number of machines in the resulting sequence required to achieve the same efficiency score.
Examples
Example 1
machineCapacity = [1, 2, 2, 1, 1]return = 3Constraints
1 ≤ n ≤ 2×10^50 ≤ machineCapacity[i] ≤ 10^9
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026