#2680

Maximum OR

specialist · 985 · lc medium +32 · verified · 42.7% accepted · 423 likes · top 24%

Description

You are given a 0-indexed integer array nums and an integer k. In each operation, pick any element and multiply it by 2. Perform at most k operations. Return the maximum possible bitwise OR of all elements in nums.

Example 1:

Input: nums = [12,9], k = 1
Output: 30
Explanation: If we apply the operation to index 1, our new array nums will be equal to [12,18]. Thus, we return the bitwise or of 12 and 18, which is 30.

Example 2:

Input: nums = [8,1,2], k = 2
Output: 35
Explanation: If we apply the operation twice on index 0, we yield a new array of [32,1,2]. Thus, we return 32|1|2 = 35.

Code

1
2
3