Peak Process Memory
Updated
Problem statement
A server runs a list of processes. Process i is given as processes[i] = [start, end, memory]: it starts at time start, stops at time end, and uses memory units of memory while it runs.
A process is running at time t when start <= t < end. It uses its memory at its start time, but no longer at its end time. So if one process ends at time t and another starts at time t, they do not run together.
The total memory at time t is the sum of memory over all processes running at t. The peak is the largest total memory at any time.
Find when the peak happens:
peakStartis the first time the total memory becomes equal to the peak.peakEndis the first time afterpeakStartwhen the total memory drops below the peak.
Several processes can start or stop at the same time. Apply all changes at the same time together before you look at the total. If the total stays at the peak because one process stops and another starts at that moment, the peak has not ended. If the peak happens again later, after the total has dropped, ignore the later stretch.
Return [peak, peakStart, peakEnd].
Function
findMemoryPeak(processes: int[][]) → int[]Examples
Example 1
processes = [[5,8,2],[1,4,3],[7,9,4],[2,6,5]]return = [8,2,4]Sorted by start time, the processes are [1, 4, 3], [2, 6, 5], [5, 8, 2] and [7, 9, 4]. The total memory is 3 from time 1, 8 from time 2, 5 from time 4 (the first process stops), 7 from time 5, 2 from time 6, 6 from time 7, 4 from time 8 and 0 from time 9.
The largest total is 8. It starts at time 2 and lasts until time 4, when it drops to 5. The answer is [8, 2, 4].
Example 2
processes = [[0,5,6],[5,9,6],[9,12,2]]return = [6,0,9]From time 0 the first process uses 6. At time 5 it stops and the second process starts, so they never run at the same time and the total stays 6. At time 9 the second process stops and the third one starts, so the total drops to 2. At time 12 it is 0.
The largest total is 6. It begins at time 0 and does not drop until time 9; the changes at time 5 do not end it. The answer is [6, 0, 9].
Example 3
processes = [[10,20,7],[30,40,4],[35,50,3]]return = [7,10,20]The total is 7 from time 10 to time 20, then 0. It is 4 from time 30, 7 from time 35 (4 + 3), and 3 from time 40 until time 50.
The largest total, 7, happens twice: from 10 to 20 and from 35 to 40. Return the earlier one: [7, 10, 20].
Constraints
1 <= processes.length <= 10^4processes[i].length == 30 <= start < end <= 10^91 <= memory <= 10^4
More Nutanix Onsite Interview questions
- Design Hit CounterONSITE INTERVIEW · Seen Oct 2026
- Minimum Operations to Transform ArrayONSITE INTERVIEW · Seen Jun 2026
- Count Connected Components in an Undirected GraphONSITE INTERVIEW · Seen Aug 2025
- LRU CacheONSITE INTERVIEW · Seen Aug 2025
- Running Median of a Multilevel Linked List in Level OrderONSITE INTERVIEW · Seen Aug 2025
- Custom Array IteratorONSITE INTERVIEW · Seen Dec 2024
- Collapse Runs of Repeated CharactersONSITE INTERVIEW · Seen Nov 2022
- Anagram Words in a SentenceONSITE INTERVIEW · Seen Apr 2022
- Sudoku SolverONSITE INTERVIEW · Seen Feb 2022
- Distance Sums to Special Nodes in a Weighted TreeONSITE INTERVIEW · Seen Aug 2021
Similar questions at other companies
- Unique Active Pins by Time SegmentPinterest · ONSITE INTERVIEWPinterest interview questions
- Calendar Event System with Pagination and IntersectionLead Bank · ONSITE INTERVIEWLead Bank interview questions
- Top Error Types in a Time WindowNotion · ONSITE INTERVIEWNotion interview questions
- Highlight and Rank Overlapping CitationsHarvey · ONSITE INTERVIEWHarvey interview questions
- Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
- Merchant Capacity Interval MergeDoorDash · PHONE SCREENDoorDash interview questions
- Free Time for Every Meeting RoomScale AI · PHONE SCREENScale AI interview questions
- Merge Collinear Point SegmentsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Worker Management (Promotion Track), Part 4: Full-Shift Double PayAirbnb · OAAirbnb interview questions
- Lab and Consultation Appointment MatchingAssort Health · PHONE SCREENAssort Health interview questions
Nutanix interview experiences
- Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
- Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
- Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
- Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
- Nutanix Intern Debugging Round and Interviews: 25 Experiences