Skip to content

Corporate Flight Bookings

MediumIntervals
Decode it first. Clues, constraints, pattern and plan before any code.

There are n flights labelled 1 to n. Each booking [first, last, seats] reserves seats seats on every flight from first to last, inclusive. Return a list answer of length n where answer[i] is the total seats reserved on flight i + 1.

bookings = [[1, 2, 10], [2, 3, 20], [2, 5, 25]], n = 5
  →  [10, 55, 45, 25, 25]
 
bookings = [[1, 2, 10], [2, 2, 15]], n = 2
  →  [10, 25]

Constraints

  • 1 <= n <= 2 * 10^4
  • 1 <= bookings.length <= 2 * 10^4
  • 1 <= first <= last <= n
  • 1 <= seats <= 10^4