Maximize minimum element of an array
Anonymous User
5203

Given an array: [1 2 4 7] and operation Number: (k=11) We can perform below operation at max 11 times:

  • Increase any element by 1.
    We have to maximize the min element from the array

Example 1:
[1 2 4 7] , operationNumber = (k = 11)

[1 2 4 7] -> (after 11 operaton) -> 6 6 6 7
Min element is 6.

Example 2: [ 3 1 1 1 ], operation Number: (k = 4)

[3 1 1 1] -> (after 4 operation) -> [3 3 2 2]
Min element is 2

We can use priorityQueue (min heap) and keep performing below operation k number of times:

  1. Extract min element x, add x+1 back to heap

After doing k operation top element in heap is answer, But TC is in power of O(klogn) which is very high, Any another efficient approach, please?

PS: This was not asked in interview, but seems important problem, and can be asked in interview.

Comments (6)