Problem · Array

Get Max Or Sum

MediumMicrosoftOA
See Microsoft hiring insights

Before optimizing operating system resource management, resources are distributed across n system locations. The objective is to consolidate them into a maximum of k locations.

The cost associated with relocating all the resources from location i to another location j is determined by the value costToTransfer[i][j], the computational overhead required. The overall cost is the sum of the resource transfers. Locations are numbered from 0 to n - 1.

Determine the minimum cost required to consolidate the resources to k locations.

Note:

A resource can be transferred from location to location through an intermediate location k.

For an array of n integers, arr[n], perform the following operation up to some integer k times.

  • Choose an index i such that 1 ≤ i ≤ n.
  • Choose an index i such that 1 ≤ i ≤ n
  • Replace arr[i] with arr[i] * 2
  • The or-sum is the bitwise-or of all elements in the final array after the operations. Return the maximum or-sum possible.

    Function Description

    Complete the function getMaxOrSum in the editor.

    getMaxOrSum has the following parameters:

    1. int arr[n]: the original array
    2. int k: the maximum number of operations

    Returns

    int: the maximum or-sum possible

    Examples
    01 · Example 1
    arr = [12, 9]
    k = 1
    return = 30
    These outcomes are possible after 1 operation. Select i = 1: The final array is arr = [24, 9]. Its or-sum is 25. Select i = 2: The final array is arr = [12, 18]. Its or-sum is 30. Of these, 30 is the greater or-sum. Return 30.
    More Microsoft problems
    drafts saved locally
    public int getMaxOrSum(int[] arr, int k) {
      // write your code here
    }
    
    arr[12, 9]
    k1
    expected30
    sign in to submit