Problem Β· Intervals

Maximum Concurrent Processes (Bar Raiser Round)

● MediumAmazonFULLTIMEONSITE INTERVIEW
See Amazon hiring insights

πŸ‡ FastPrep match note: This version is based on a reported Amazon SDE2 full-time onsite Bar Raiser round prompt and should match the core task about 90-95%: given process running intervals, return the maximum number running at the same time.

The main uncertainty is whether the original wording explicitly counted endpoints as running; the reported example only reaches 3 if time 3 belongs to both [1, 3] and [3, 6], so we make the inclusive endpoint rule explicit and add a few practice examples and constraints for clarity.

You are given a list of processes. Each process has a running interval represented as [start, end].

A process is considered running at every integer time from start through end, inclusive.

Return the maximum number of processes running at the same time.

Function Description

Complete the function maxConcurrentProcesses in the editor.

maxConcurrentProcesses has the following parameter:

  • int intervals[n][2]: each interval is [start, end], where start <= end.

Returns

int: the maximum number of processes running concurrently at any time.

Follow-up

How would your answer change if each interval were half-open, meaning [start, end), where the process stops running before end?

Examples
01 Β· Example 1
intervals = [[1, 3], [2, 5], [3, 6]]
return = 3

At time 3, all three processes are running. Since intervals are inclusive, both [1, 3] and [3, 6] include time 3.

02 Β· Example 2
intervals = [[1, 2], [3, 4], [5, 6]]
return = 1

No two processes overlap, so the maximum number of concurrent processes is 1.

03 Β· Example 3
intervals = [[1, 10], [2, 3], [4, 5], [6, 7]]
return = 2

The long-running process overlaps with each shorter process, but the shorter processes do not overlap with one another.

04 Β· Example 4
intervals = [[1, 4], [2, 6], [4, 8], [6, 9]]
return = 3

At time 4, [1, 4], [2, 6], and [4, 8] are all running because interval endpoints are inclusive.

Constraints
  • 1 <= intervals.length <= 100000
  • 0 <= start <= end <= 1000000000
  • All start and end values are integers.
  • Intervals are inclusive: [start, end].
More Amazon problems
drafts saved locally
public int maxConcurrentProcesses(int[][] intervals) {
  // write your code here
}
intervals[[1, 3], [2, 5], [3, 6]]
expected3
checking account