Skip to content
Decoder

Corporate Flight Bookings

Medium

Problem

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.

Example 1

bookings = [[1, 2, 10], [2, 3, 20], [2, 5, 25]], n = 5

Example 2

  →  [10, 55, 45, 25, 25]

Example 3

bookings = [[1, 2, 10], [2, 2, 15]], n = 2

Example 4

  →  [10, 25]

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.