Get Max Or Sum
Updated
Problem 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 interview questions
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Maximum Escape Game ScoreOA · Seen Nov 2026
- Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
Similar questions at other companies
- Minimize the Maximum Array ElementChubb · OAChubb interview questions
- Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
- Server SelectionPoint72 · OAPoint72 interview questions
- Minimum Servers for an Exact LoadJP Morgan Chase · OAJP Morgan Chase interview questions
- Maximize PartitionsAmazon · OA
- Fewest Steps to Build an Array from ZerosExpedia · OAExpedia interview questions
- Maximum XOR Elimination ScoreRippling · OARippling interview questions
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Minimum Row Deletions to Prevent a Target ORInMobi · ONSITE INTERVIEWInMobi interview questions
- Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon · OA
Microsoft interview experiences
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
- Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
- Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)