Back to problems

Maximize Bitwise AND Under a Budget

Algorithm · Amazon · Hard

You are given an integer array arr, an integer K, and an integer budget C. You may increase any of the elements of arr by non-negative amounts, provided the sum of all increases you apply is at most C. Once the increases are done, choose any K elements from the array (they do not have to be adjacent) and take the bitwise AND of those K values. Return the largest bitwise AND that can be obtained this way. Example 1: Explanation: Choose the elements 4, 5 and 7. After spending…

Loading the rest of the question…