FastPrepReduce Memory Usage
Problems/Reduce Memory Usage

Reduce Memory Usage

Amazon logoAmazon● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You work in an Amazon data center and want to reduce how much main memory the running processes use.

You are given an array processes, where processes[i] is the memory used by process i, and an integer m. You must stop exactly m processes, and they must form one contiguous segment of the array.

Return the smallest possible total memory used by the processes that keep running.

Function

reduceMemoryUsage(processes: int[], m: int) → int

Examples

Example 1

processes = [10, 4, 8, 13, 20]m = 2return = 22

Removing 13 and 20 as they are consuming large memory. The remaining processes consume 10 + 4 + 8 = 22 units of memory, which is the minimum possible.

Constraints

  • 2 ≤ processes.length ≤ 10^5
  • 1 < m < 100000
  • m ≤ processes.length
  • 1 < processes[i] < 1000000000
  • The answer fits in a 32-bit signed integer (at most 2^31 - 1). The total of all processes may be larger.

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

  • Threshold AlertsGoldman Sachs · OAGoldman Sachs interview questions
  • Profit AnalysisVirtu Financial · OAVirtu Financial interview questions
  • Minimum Size Subarray SumMicrosoft · OAMicrosoft interview questions
  • Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEWOracle interview questions
  • Count Hotspot Playback WindowsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Maximum Value for Two Delivery RobotsNuro · PHONE SCREENNuro interview questions
  • Subarray with a Given SumExpedia · ONSITE INTERVIEWExpedia interview questions
  • Longest Run of Ones After Flipping k ZerosC3.ai · PHONE SCREENC3.ai interview questions
  • Count Strictly Increasing Contiguous WindowsIBM · OAIBM interview questions
  • Minimum Positive Starting ValueBooking.com · OA

Interview reports that mention this question

  • Amazon New Grad OA Problems: Every Task We Have (Part 3 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 int reduceMemoryUsage(int[] processes, int m) {
      // write your code here
    }

}
Checking account…