Reduce Memory Usage
Updated
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) → intExamples
Example 1
processes = [10, 4, 8, 13, 20]m = 2return = 22Removing 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^51 < m < 100000m ≤ processes.length1 < 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