This is a verified interview question from Amazon. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Calculate Optimal Bandwidth" covers key patterns like Other.
"You are part of Amazon's Network Infrastructure Division and you are working on a project to maximize data transfer efficiency across its network of data centers. You are given n data centers, and the bandwidth capacity of each center is given in an integer array named capacity. There are connectionCount data streams that needs to be routed through two data centers, one as the primary route and the other as the failover. Each data stream must use a unique pair of data centers for its routing. The bandwidthRate for each data stream is defined as the sum of the capacity of its primary and failover data centers. Given an integer array capacity and an integer connectionCount, find the maximum total bandwidthRate that can be obtained by optimally choosing unique pair of routes for each data stream. Note: A pair of data centers (x, y) is said to be unique if no other stream has selected the same pair. However, the pairs (x, y) and (y, x) are treated as different routes. It is also possible to select the same data center for primary and failover routes, which means that (x, x) is a valid pair for the connection. ### Example 1: Input: capacity = [5, 3, 6], connectionCount = 4 Output: 44 Explanation: The data streams can select their routes among the following 9 possible data center pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3). (Assuming 1-based indexing of capacity array). However each data stream must select a unique pair of data centers. To achieve the maximum total bandwidthRate, the data streams can optimally choose the pairs (3, 5), (3, 3), (5, 6), (6, 6) to obtain the maximum sum of bandwidthRate = (6 + 6) + (6 + 6) + (5 + 6) + (5 + 6) = 44. ### Constraints: - 1 <= n <= 2 * 10^5 - 1 <= capacity[i] <= 2 * 10^5 - 1 <= connectionCount <= min(10^9, n * (n - 1) / 2)"
Join thousands of developers practicing for Amazon.