Skip to content
MediumArraysAI interview only

Corporate Flight Bookings

Asked atamazongooglegoldman-sachs

01 · Problem

There are n flights numbered 1 to n. You are given a list bookings, where bookings[i] = [first, last, seats] means seats seats were reserved on every flight from first through last, inclusive.

Return an array answer of length n where answer[i] is the total number of seats reserved on flight i + 1.

02 · Examples

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

Flight 1: 10. Flight 2: 10 + 20 + 25 = 55. Flight 3: 20 + 25 = 45. Flights 4 and 5: 25 each.

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

Flight 1 only gets the first booking (10). Flight 2 gets 10 + 15 = 25.

Example 03
Input
bookings = [[3,3,5],[1,4,1]], n = 4
Output
[1,1,6,1]

Every flight gets 1 seat from the second booking, and flight 3 also gets 5, giving [1,1,6,1].

03 · Constraints

  • 011 <= n <= 2 * 104
  • 021 <= bookings.length <= 2 * 104
  • 03bookings[i].length == 3
  • 041 <= first <= last <= n
  • 051 <= seats <= 104

04 · Optimal complexity

Time
O(n + k)
Space
O(n)
05 · Two ways to work on it

Practice it alone or rehearse it as an interview.

Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.