You're given a 0-indexed integer array nums and an integer k representing the maximum number of operations you can perform.
In each operation, you can choose any index i where 0 โค i < nums.length - 1 and merge the adjacent elements nums[i] and nums[i + 1] into a single element with value nums[i] & nums[i + 1] (bitwise AND).
Your goal is to find the minimum possible value of the bitwise OR of all remaining elements after performing at most k operations.
Key insight: Since bitwise AND always produces a value โค both operands, and OR combines all set bits, we want to strategically merge elements to minimize the final OR result.
Input & Output
Visualization
Time & Space Complexity
Initial heap construction takes O(n log n), then we perform k operations each taking O(log n)
Priority queue stores at most n-1 possible merges
Constraints
- 1 โค nums.length โค 105
- 0 โค nums[i] โค 230
- 0 โค k โค nums.length - 1
- Each operation reduces array size by 1