FastPrepPeak Resource Usage Across Weighted Intervals

Peak Resource Usage Across Weighted Intervals

Tekion logoTekion● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Each half-open interval [start, end) consumes a positive number of resources while active. Return the maximum total resource usage at any instant.

An interval ending at time t is inactive before an interval starting at t is counted.

Function

peakResourceUsage(intervals: int[][], resources: int[]) → int

Examples

Example 1

intervals = [[1,4],[3,5],[4,6]]resources = [3,2,4]return = 6

Case 1 exercises the documented deterministic contract.

Example 2

intervals = [[0,1]]resources = [7]return = 7

Case 2 exercises the documented deterministic contract.

Example 3

intervals = [[1,2],[2,3]]resources = [5,9]return = 9

Case 3 exercises the documented deterministic contract.

Constraints

  • 1 <= intervals.length == resources.length <= 200000.
  • 0 <= start < end <= 10^9.
  • The total active resource count fits a signed 32-bit integer.

More Tekion problems

See Tekion hiring insights
public int peakResourceUsage(int[][] intervals, int[] resources) {
    // Write your code here.
}
intervals[[1,4],[3,5],[4,6]]
resources[3,2,4]
expected6
Checking account…