← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Given an array arr[] of N integers and an integer K, the task is to minimize the sum of the given array by performing at most K operations, where each operation involves reducing an array element arr[i] to floor(arr[i]/2). To obtain the minimum possible sum, always halve the largest element in each operation. This greedy choice gives the maximum reduction per step and can be efficiently implemented with a max-heap (priority queue) that supports extracting and updating the current maximum in O(log N) time. After performing exactly K such operations, return the sum of the remaining elements in the array.