FastPrepFastPrep
Problem Brief

Get Max Or Sum

OA

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

    1Example 1

    Input
    arr = [12, 9], k = 1
    Output
    30
    Explanation
    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.
    public int getMaxOrSum(int[] arr, int k) {
      // write your code here
    }
    
    Input

    arr

    [12, 9]

    k

    1

    Output

    30

    Sign in to submit your solution.