Max Bitwise AND With Increments
HardBit Manipulation ยท Amazon
Given an integer array nums and integers k and budget, you may add 1 to any element of nums, any number of times, as long as the total number of additions is at most budget. Afterwards, choose k elements at different indices.
Return the largest bitwise AND of the chosen elements that can be achieved.
Example 1
- Input:
- nums = [5, 2, 6], k = 2, budget = 3
- Output:
- 7
- Explanation
- Raise 5 to 7 (2 additions) and 6 to 7 (1 addition); choosing those two gives 7 & 7 = 7.
Example 2
- Input:
- nums = [12, 5], k = 2, budget = 6
- Output:
- 9
- Explanation
- Raising 12 to 13 and 5 to 9 costs 5 and gives 13 & 9 = 9.
Example 3
- Input:
- nums = [0, 0, 0], k = 3, budget = 5
- Output:
- 1
Constraints
1 <= nums.length <= 10^51 <= k <= nums.length0 <= nums[i] <= 10^90 <= budget <= 10^9