PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Maximize memory capacity with primary-backup servers

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic reasoning in constrained pairings and resource allocation, focusing on maximizing aggregate memory under pairwise feasibility constraints while managing large input sizes.

  • hard
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Maximize memory capacity with primary-backup servers

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Take-home Project

You are helping to optimize the capacity of a cloud system. There are `n` servers, where `n` is always even. The memory capacity of the *i*-th server is given by an integer array `memory` of length `n`. When there are `n = 2 * x` servers: - Exactly `x` servers will be chosen as **primary** servers. - The remaining `x` servers will be **backup** servers. For every primary server `P`, there must exist a **distinct** backup server `B` such that: > `memory[B] >= memory[P]` (Each server can be used as either primary or backup in exactly one such pair, so the `n` servers are partitioned into `x` (primary, backup) pairs.) The **system memory capacity** is defined as the sum of the memory capacities of all primary servers: > `capacity = sum(memory[P] over all primary servers P)` Your task is to determine the **maximum possible system memory capacity** that can be obtained by: - Partitioning the `n` servers into `n/2` disjoint (primary, backup) pairs, and - Respecting the constraint `memory[backup] >= memory[primary]` within each pair. ### Input - An even integer `n` (number of servers). - An integer array `memory` of length `n`, where `memory[i]` is the memory capacity of the *i*-th server. You may assume: - `2 <= n <= 2 * 10^5`, and `n` is even. - `1 <= memory[i] <= 10^9`. ### Output - Return a single integer: the **maximum possible system memory capacity**. ### Complexity requirement Design an algorithm efficient for `n` up to about `2 * 10^5` (i.e., significantly better than `O(n^2)` time).

Quick Answer: This question evaluates algorithmic reasoning in constrained pairings and resource allocation, focusing on maximizing aggregate memory under pairwise feasibility constraints while managing large input sizes.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
  • Find the Most Common Visit Pattern - Amazon (hard)
  • Maximize Value Under a Budget - Amazon (medium)
Amazon logo
Amazon
Oct 1, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
2
0

You are helping to optimize the capacity of a cloud system.

There are n servers, where n is always even. The memory capacity of the i-th server is given by an integer array memory of length n.

When there are n = 2 * x servers:

  • Exactly x servers will be chosen as primary servers.
  • The remaining x servers will be backup servers.

For every primary server P, there must exist a distinct backup server B such that:

memory[B] >= memory[P]

(Each server can be used as either primary or backup in exactly one such pair, so the n servers are partitioned into x (primary, backup) pairs.)

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

capacity = sum(memory[P] over all primary servers P)

Your task is to determine the maximum possible system memory capacity that can be obtained by:

  • Partitioning the n servers into n/2 disjoint (primary, backup) pairs, and
  • Respecting the constraint memory[backup] >= memory[primary] within each pair.

Input

  • An even integer n (number of servers).
  • An integer array memory of length n , where memory[i] is the memory capacity of the i -th server.

You may assume:

  • 2 <= n <= 2 * 10^5 , and n is even.
  • 1 <= memory[i] <= 10^9 .

Output

  • Return a single integer: the maximum possible system memory capacity .

Complexity requirement

Design an algorithm efficient for n up to about 2 * 10^5 (i.e., significantly better than O(n^2) time).

Submit Your Answer

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,500+ 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.