Pair network nodes to maximize the sum of minimum bandwidths
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
Overview: Given a sorted array of node bandwidth capacities with even length, pair every node exactly once so that the sum of each pair's smaller capacity is as large as possible. It tests greedy reasoning, an exchange argument for correctness, and care with 64-bit totals.
Constraints
- 2 <= len(nodes) <= 10^5, and len(nodes) is even
- 1 <= nodes[i] <= 10^9
- nodes is sorted in non-decreasing order
Examples
Input: ([1, 1],)
Expected Output: 1
Explanation: Smallest valid input: one pair of equal values at the lower bound.
Input: ([3, 8],)
Expected Output: 3
Explanation: One pair of distinct values contributes the smaller value.
Hints
- The node with the smallest capacity contributes exactly its own capacity to whichever pair it joins. Ask which partner choice gives up the least.
- Work through [1, 2, 3, 4] by hand: list all three possible pairings and compare their totals.
- The total can reach 5 * 10^13, past the signed 32-bit range, so choose an accumulator type that holds it.