FastPrepChannels Max Quality

Channels Max Quality

Amazon logoAmazon● MediumFULLTIMEOA

Problem statement

You are given a list of packets of varying sizes and there are n channels.

  • Each of the n channel must have a single packet
  • Each packet can only be on a single channel

The quality of a channel is described as the median of the packet sizes on that channel. The total quality is defined as sum of the quality of all channels (round to integer in case of float).

Given the packet sizes and num of channels, find the maximum quality.

Function

calculateMedianSum(packets: int[], n: int) → int

Complete the function calculateMedianSum in the editor.

calculateMedianSum has the following parameters:

  1. int[] packets: an array of integers
  2. int n: the number of channels

Returns int: the sum of the medians of each channel

Examples

Example 1

packets = [1, 2, 3, 4, 5]n = 2return = 8

If packet {1, 2, 3, 4} is sent to channel 1, the median of that channel would be 2.5 If packet {5} is sent to channel 2, its median would be 5 Max total quality is 2.5 + 5 = 7.5 ~ 8

Example 2

packets = [5, 2, 2, 1, 5, 3]n = 2return = 7

channel 1 -> {2, 2, 1, 3,}, median = 2 channel 2 -> {5, 5}, median = 5 total quality 2 + 5 = 7

Constraints

  • Unknown for now

More Amazon problems

See Amazon hiring insights
Saved
public int calculateMedianSum(int[] packets, int n) {
  // write your code here
}
packets[1, 2, 3, 4, 5]
n2
expected8
Checking account…