Detect a Server RAM Capacity Breach
Updated
Problem statement
A server cluster runs jobs described by parallel arrays ram, startTimes, and endTimes. Job i consumes ram[i] units during the half-open interval [startTimes[i], endTimes[i]).
Return true if the total RAM used by active jobs is ever strictly greater than totalCapacity. Otherwise, return false. A job ending at a time releases its RAM before any job starting at that same time becomes active.
Function
exceedsRamCapacity(ram: long[], startTimes: int[], endTimes: int[], totalCapacity: long) → booleanExamples
Example 1
ram = [4,3,5]startTimes = [1,2,6]endTimes = [5,7,8]totalCapacity = 6return = trueFrom time 2 through time 5, the first two jobs use 7 units, which exceeds 6.
Example 2
ram = [4,3,2]startTimes = [1,5,5]endTimes = [5,7,6]totalCapacity = 5return = falseAt time 5, the 4-unit job has ended before the 3-unit and 2-unit jobs start, so usage reaches but never exceeds 5.
Constraints
0 <= ram.length <= 2 * 10^5.ram.length == startTimes.length == endTimes.length.1 <= ram[i] <= 10^9.0 <= startTimes[i] < endTimes[i] <= 10^9.1 <= totalCapacity <= 10^18.
More Myntra interview questions
Similar questions at other companies
- Meeting Scheduling SystemHevo Data · ONSITE INTERVIEW
- Peak Task Concurrency IntervalsGoogle · ONSITE INTERVIEW
- Peak Chat Load Across AgentsCresta · PHONE SCREEN
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Brightest Position on a StreetCapital One · OA
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEW
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEW
- Maximum Concurrent Processes (Bar Raiser Round)Amazon · PHONE SCREEN · ONSITE INTERVIEW
- Maximum Intervals Overlapping a Fixed-Length WindowBooking.com · ONSITE INTERVIEW
- Meeting Rooms IISalesforce · ONSITE INTERVIEW