All practice tasks

Coding (Algo)

Weighted Job Schedule

Binary search · Hard

A maintenance worker can run one job at a time. Jobs have fixed windows and different recovery value.

Return the maximum value of a non-overlapping subset of jobs.

Input

Call

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

Input object

{ jobs:{start:integer,end:integer,value:integer}[] }. start < end; value may be negative

What each field means

  • jobs — available jobs, each with start, end and a signed integer value.

Output

Return value and rules

  • Return the largest total value obtainable from non-overlapping jobs.
  • A job may start exactly when another selected job ends.
  • Selecting no jobs is allowed and has value 0. Return the value, not the selected jobs.

Constraints

  • 0 <= jobs.length <= 100000
  • Time bounds are [0,1000000000]; values are [-1000000,1000000]
  • Do not mutate or return the selected jobs.

Examples

Example 1

{
  "jobs": [
    {
      "start": 0,
      "end": 3,
      "value": 5
    },
    {
      "start": 3,
      "end": 5,
      "value": 6
    },
    {
      "start": 0,
      "end": 5,
      "value": 10
    }
  ]
}

Returns

11

Example 2

{
  "jobs": []
}

Returns

0

Required complexity

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

What this task practices

Weighted Job Schedule 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 hard 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.