There are n servers, where the power of the jth server is given by arr[j].
These servers are grouped into clusters of size three. The power of a cluster, denoted as cluster_power, is defined as the median of the power values of the three servers in the cluster. Each server can be part of at most one cluster, and some servers may remain unused.
The total system power, called max_result, is the sum of the power of all the clusters formed. The task is to find the maximum possible max_result.
Complete the function maximizeClusterPower in the editor.
maximizeClusterPower has the following parameters:
- 1.
int n: the number of servers - 2.
int[] arr: an array of integers representing the power of each server
Returns
int: the maximum possible system power
n = 7 arr = [8, 6, 3, 4, 4, 5, 6] return = 11
The maximum number of clusters that can be formed is 2, with one server remaining unused.
One possible way to form the clusters is to select the 1st, 2nd, and 3rd servers for the first cluster, and the 4th, 6th, and 7th servers for the second cluster. The cluster_power of the first cluster [8, 6, 3] will be 6 (the median), and the cluster_power of the second cluster [4, 5, 6] will be 5 (the median).
Thus, the max_result will be 6 + 5 = 11.
- Minimum Operations to Make the Integer ZeroSeen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Minimum Operations to Make Array ValidOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
public int maximizeClusterPower(int n, int[] arr) {
// write your code here
}