FastPrepMinimize Array Sum After K Halving Operations

Minimize Array Sum After K Halving Operations

DocuSign logoDocuSign● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Perform exactly k operations on an array of nonnegative integers. In one operation, choose an element, replace it by ceil(value/2), and put it back.

Return the minimum possible array sum after all operations.

Function

minimumSumAfterHalves(values: int[], k: int) → long

Examples

Example 1

values = [10,20,7]k = 4return = 14

Repeatedly reducing a current maximum yields the minimum sum.

Example 2

values = [1,1]k = 3return = 2

Halving one leaves it at one, so the sum stays two.

Example 3

values = [5]k = 2return = 2

Five becomes three, then two.

Constraints

  • 1 <= values.length <= 100000.
  • 0 <= values[i] <= 10^9.
  • 0 <= k <= 100000.

More DocuSign problems

See DocuSign hiring insights
public long minimumSumAfterHalves(int[] values, int k) {
    // write your code here
}
values[10,20,7]
k4
expected14
Checking account…