FastPrepRepeated Maximum and Minimum Request Score
Problem · Array

Repeated Maximum and Minimum Request Score

Learn this problem
MediumAmazon logoAmazonINTERNOA
See Amazon hiring insights

Problem statement

Process requests operations on the integer array values. During each operation:

  1. Read the current minimum and current maximum value.
  2. Add their sum to a running score.
  3. Choose any one occurrence of the current maximum and decrease it by 1.

Return the score after all requests. When several entries equal the maximum, choosing any of them produces the same multiset for the next operation.

Function

maximumMinimumRequestScore(values: int[], requests: int) → long

Examples

Example 1

values = [3,1,4]requests = 2return = 9

The request sums are 4 + 1 = 5 and then 3 + 1 = 4, totaling 9.

Example 2

values = [5]requests = 3return = 24

The same element is both minimum and maximum, producing 10, 8, and 6.

Example 3

values = [1,1,1]requests = 4return = 4

After each tied maximum is decremented, zero becomes the minimum for later requests.

Constraints

  • 1 <= values.length, requests <= 100000.
  • -10^9 <= values[i] <= 10^9.
  • The final score fits in a signed 64-bit integer.

More Amazon problems

drafts saved locally
public long maximumMinimumRequestScore(int[] values, int requests) {
  // write your code here
}
values[3,1,4]
requests2
expected9
checking account