Reliability algorithms

Peak work in flight

Estimate the maximum simultaneously active requests from completed request intervals.

In production

Peak in-flight work sizes pools and autoscales. Counting ends after starts at the same timestamp understates the peak.

What it must return

Return the maximum number of intervals that overlap at any instant, treating an end before a start at the same time.

  • Each interval is [start, end) with start <= end. Zero-length intervals count as no work. An end at time t is processed before a start at t. Return the maximum active count.
  • Do not mutate input values. Use the Python standard library only.

Edge cases

  • Convert intervals into start and end events.
  • At equal timestamps, process ends before starts.
  • Do not mutate the input.

Signature

peak_concurrency(intervals)

Hints

  1. Second hint

  2. A partial sketch

The reference solution opens after the last hint.

solution.py · Python

Loading editor…

Overlap

intervals

[
  [
    0,
    3
  ],
  [
    1,
    4
  ],
  [
    2,
    5
  ]
]

Expected

3

Each run uses a fresh Python runtime in this browser, with a 3-second limit and a Stop button. The first run downloads the runtime. 0 of 10 in Reliability algorithms passed in Python on this device.

Next: Retry delays, partly written