Corporate Flight Bookings

Prefix Sums, problem 6 of 7

Corporate Flight Bookings

Medium

LC #1109

difference arrayprefix sum

Not attempted yet

There are n flights numbered 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.

Example 1

Input: bookings = [[1, 2, 10], [2, 3, 20],
                   [2, 5, 25]], n = 5
Output: [10, 55, 45, 25, 25]

Flight 2 gets 10 + 20 + 25 = 55.

Example 2

Input: bookings = [[1, 2, 10], [2, 2, 15]], n = 2
Output: [10, 25]

Example 3

Input: bookings = [[3, 3, 5]], n = 4
Output: [0, 0, 5, 0]

Constraints

  • 1 ≤ n ≤ 2 · 10⁴
  • 1 ≤ len(bookings) ≤ 2 · 10⁴
  • 1 ≤ first ≤ last ≤ n
  • 1 ≤ seats ≤ 10⁴

Python

Loading draft…

Test results

7 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 4 hidden

Run examples, then submit all tests.