All practice tasks

Coding (Algo)

Peak Worker Demand

Sweep line · Medium

An async job service knows the half-open execution intervals of accepted jobs. It needs enough workers for the busiest instant.

Return the maximum number of simultaneously active jobs.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ jobs:[start:integer,end:integer][] }

Input rules

  • Every job has start < end.

What each field means

  • jobs — [start, end] intervals. A job is active at its start, but not at its end.

Output

Return value and rules

  • Return the largest number of jobs active at the same time.
  • A job ending at time t does not overlap one starting at t.
  • No jobs require zero workers.

Constraints

  • 0 <= jobs.length <= 100000
  • 0 <= start < end <= 1000000000

Examples

Example 1

{
  "jobs": [
    [
      0,
      4
    ],
    [
      1,
      3
    ],
    [
      3,
      5
    ]
  ]
}

Returns

2

Example 2

{
  "jobs": []
}

Returns

0

Required complexity

O(n log n) time and O(n) space

What this task practices

Peak Worker Demand is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.