FastPrepDetect a Server RAM Capacity Breach
Problems/Detect a Server RAM Capacity Breach

Detect a Server RAM Capacity Breach

Myntra logoMyntra● MediumINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report supplies RAM usage, start times, end times, and a capacity-breach decision, and names difference-array, prefix-sum, and sweep-line techniques. It omits interval boundaries, tie behavior, bounds, and examples; the judged core task matches at about 92%.

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) → boolean

Examples

Example 1

ram = [4,3,5]startTimes = [1,2,6]endTimes = [5,7,8]totalCapacity = 6return = true

From 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 = false

At 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 problems

  • Maximum Capped Histogram Area After One RemovalOA · Seen May 2026
  • Maximum Capped Histogram Area After One RemovalOA · Seen May 2026
  • Minimum Route Reversals to Warehouse ZeroONSITE INTERVIEW · Seen May 2026
All Myntra interview questionsSee Myntra hiring insights
Saved
public boolean exceedsRamCapacity(long[] ram, int[] startTimes, int[] endTimes, long totalCapacity) {
    // Return true exactly when active RAM usage exceeds capacity.
}
Checking account…