Repeated Maximum and Minimum Request Score
Updated
Problem statement
You are given an integer array values and a count requests. Process requests operations, one after another. In each operation:
- Find the current smallest value and the current largest value.
- Add those two values to a running score.
- Pick one copy of the current largest value and decrease it by
1.
Return the score after all requests. If several entries tie for the largest value, it does not matter which one you pick. The next operation sees the same collection of values either way.
Function
maximumMinimumRequestScore(values: int[], requests: int) → longExamples
Example 1
values = [3,1,4]requests = 2return = 9The first request adds the largest and smallest values: 4 + 1 = 5. The largest value then drops by one. The second request adds 3 + 1 = 4. The total is 9.
Example 2
values = [5]requests = 3return = 24The single element is both the smallest and the largest value, so each request adds it twice. It drops by one after each request, so the requests add 10, 8, and 6. The answer is their total.
Example 3
values = [1,1,1]requests = 4return = 4The first request adds one plus one and lowers one entry to zero. From then on, zero is the smallest value. The next two requests each add one, and each lowers another entry to zero. The last request adds nothing, so the total is four.
Constraints
1 <= values.length, requests <= 100000.-10^9 <= values[i] <= 10^9.- The final score fits in a signed 64-bit integer.
More Amazon Online Assessment questions
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Get Smallest Base SegmentOA · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Find Total WeightJP Morgan Chase · OAJP Morgan Chase interview questions
- Update Pod Counts From LogsSalesforce · OASalesforce interview questions
- Apply Binary State OperationsZipRecruiter · OAZipRecruiter interview questions
- Shortest-Job-First Process SchedulingByteDance · PHONE SCREENByteDance interview questions
- Dynamic Batch Completion TimesAmbience Healthcare · PHONE SCREEN
- Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
- Cursor-Based Pagination Over Sorted LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Issue and Reuse 16-Bit TokensMeta · ONSITE INTERVIEWMeta interview questions
- Finish Ordered CPU Tasks with the Fewest CPUsGoogle · PHONE SCREENGoogle interview questions
- Weighted Server Load Balancer with TTLStripe · ONSITE INTERVIEWStripe interview questions