FastPrepMaximize Center A Package Benefit
Problems/Maximize Center A Package Benefit

Maximize Center A Package Benefit

Amazon logoAmazon● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An Amazon intern online assessment report describes linked pairs of packages, independent packages, the goal of getting the most benefit for Center A, and a greedy order that goes from the largest combined benefit down. We chose how the input is given, the tie rule, the method name, the examples, and the number limits.

Two distribution centers, A and B, split n packages between them. Package i is worth benefitA[i] to Center A and benefitB[i] to Center B.

Some packages are linked in pairs. The array linkedPairs holds these pairs [x, y], and no package is in more than one pair. In each linked pair, one package goes to A and the other goes to B. A gets the package with the larger A-benefit.

Packages that are not in any linked pair are independent. Sort them from the largest benefitA[i] + benefitB[i] down to the smallest. If two packages tie, the one with the smaller index comes first. Then hand them out in turns, starting with A: A gets the first package, B gets the second, A gets the third, and so on.

Return Center A's total benefit: what it gets from the linked pairs plus what it gets from the independent packages.

Function

maximizeCenterABenefit(benefitA: int[], benefitB: int[], linkedPairs: int[][]) → long

Examples

Example 1

benefitA = [8,3,7,4]benefitB = [1,9,2,6]linkedPairs = [[0,1]]return = 12

From linked pair [0,1], A takes package 0 for benefit 8. Independent packages 2 and 3 have combined benefits 9 and 10, so their order is 3,2. A receives package 3 for another 4, giving 12.

Example 2

benefitA = [5,2,9]benefitB = [4,8,1]linkedPairs = []return = 7

The combined benefits are 9, 10, and 10. The tie is broken by index, so the order is 1,2,0. A receives packages 1 and 0 for total benefit 2 + 5 = 7.

Example 3

benefitA = [10,4,6,12]benefitB = [2,8,7,1]linkedPairs = [[0,1],[2,3]]return = 22

All packages are linked. A takes package 0 from the first pair for benefit 10 and package 3 from the second pair for benefit 12.

Constraints

  • 1 <= benefitA.length = benefitB.length <= 200000.
  • 0 <= benefitA[i], benefitB[i] <= 10^9.
  • 0 <= linkedPairs.length <= floor(n / 2).
  • Every pair contains two distinct valid zero-based package indices.
  • No package index appears in more than one linked pair.
  • The answer fits in a signed 64-bit integer.

More Amazon Online Assessment questions

  • Lexicographically Largest IdentifierOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fill One Exact-Length Binary WindowOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026

Similar questions at other companies

  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
  • Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions

Interview reports that mention this question

  • Amazon Intern OA Problems: Every Task We Have (Part 2 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public long maximizeCenterABenefit(int[] benefitA, int[] benefitB, int[][] linkedPairs) {
        // Write your code here.
    }
}
Checking account…