Skip to content

Practice Maximum OR

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2680
LeetCode Problem

Maximum OR

Problem Statement

You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2. Return the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] that can be obtained after applying the operation on nums at most k times. Note that a | b denotes the bitwise or between two integers a and b.

Source: Maximum OR on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [12,9], k = 1
Output
30

# Example 2

Input
nums = [8,1,2], k = 2
Output
35

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9
1 <= k <= 15

Related LeetCode Problems

Practice more problems similar to Maximum OR.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.