FastPrepGet Max Or Sum
Problems/Get Max Or Sum

Get Max Or Sum

Microsoft logoMicrosoft● MediumOA

Updated Jul 2026

QuestionFunctionExamplesConstraints

Problem statement

For an array of n positive integers, arr, perform the following operation up to k times:

  1. Choose an index i such that 0 ≤ i < n.
  2. Replace arr[i] with arr[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) → long

Examples

Example 1

arr = [12, 9]k = 1return = 30

Doubling 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,000
  • 1 ≤ arr[i] ≤ 1,000,000
  • 1 ≤ 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)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long getMaxOrSum(int[] arr, int k) {
      // write your code here
    }

}
Checking account…