PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Maximize capacity with primary-backup pairing

Last updated: Mar 29, 2026

Quick Overview

This question evaluates combinatorial optimization and constrained matching skills, focusing on algorithm design, complexity analysis, and resource-allocation reasoning for maximizing aggregate capacity under pairing constraints.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Maximize capacity with primary-backup pairing

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given `n` servers, where server `i` has memory capacity `memory[i]`. A valid system must contain an **even** number of servers. If the system contains `2x` servers, then: - exactly `x` servers are designated as **primary** - exactly `x` servers are designated as **backup** - every primary server `P` must be paired with a **distinct** backup server `B` such that `memory[B] >= memory[P]` The **system memory capacity** is defined as the **sum of memory capacities of all primary servers**. Task: Given `n` and the array `memory`, compute the **maximum possible** system memory capacity over all valid choices of an even-sized subset of servers and a valid primary/backup pairing. Complete the function: - `maximumCapacity(memory)` → returns a 64-bit integer (long) Constraints: - `2 <= n <= 2 * 10^5` - `memory[i]` are integers (assume non-negative) Notes: - You may choose any even number of servers from the `n` servers (you do not have to use all servers). - Each server can be used at most once (either primary or backup, or not chosen).

Quick Answer: This question evaluates combinatorial optimization and constrained matching skills, focusing on algorithm design, complexity analysis, and resource-allocation reasoning for maximizing aggregate capacity under pairing constraints.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Implement Event Filtering and Queue Routing - Amazon (medium)
  • Determine if all courses can be completed - Amazon (medium)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
Amazon logo
Amazon
Jan 6, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
4
0
Loading...

You are given n servers, where server i has memory capacity memory[i]. A valid system must contain an even number of servers.

If the system contains 2x servers, then:

  • exactly x servers are designated as primary
  • exactly x servers are designated as backup
  • every primary server P must be paired with a distinct backup server B such that memory[B] >= memory[P]

The system memory capacity is defined as the sum of memory capacities of all primary servers.

Task: Given n and the array memory, compute the maximum possible system memory capacity over all valid choices of an even-sized subset of servers and a valid primary/backup pairing.

Complete the function:

  • maximumCapacity(memory) → returns a 64-bit integer (long)

Constraints:

  • 2 <= n <= 2 * 10^5
  • memory[i] are integers (assume non-negative)

Notes:

  • You may choose any even number of servers from the n servers (you do not have to use all servers).
  • Each server can be used at most once (either primary or backup, or not chosen).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.