Problem · Array
Get Max Or Sum
Learn this problemProblem statement
For an array of n positive integers, arr, perform the following operation up to k times:
- Choose an index
isuch that0 ≤ i < n. - Replace
arr[i]witharr[i] × 2.
The or-sum is the bitwise OR of all elements in the final array. Return the maximum possible or-sum.
Function
getMaxOrSum(arr: int[], k: int) → longExamples
Example 1
arr = [12, 9]k = 1return = 30Doubling 12 produces [24, 9], whose or-sum is 25. Doubling 9 produces [12, 18], whose or-sum is 30. Therefore, the maximum possible or-sum is 30.
Constraints
1 ≤ n ≤ 100,0001 ≤ arr[i] ≤ 1,000,0001 ≤ k ≤ 11
More Microsoft problems
- Authentication SystemOA · Seen Jul 2026
- Binary String Swap TimeOA · Seen Jul 2026
- Minimum Effort Task ScheduleOA · Seen Jul 2026
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026