Get Max Or Sum
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.
i such that 1 ≤ i ≤ n.The or-sum is the bitwise-or of all elements in the final array after the operations. Return the maximum or-sum possible.
Complete the function getMaxOrSum in the editor.
getMaxOrSum has the following parameters:
int arr[n]: the original arrayint k: the maximum number of operations
Returns
int: the maximum or-sum possible
1Example 1
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.