Mid/SeniorArrayPrefix Sum

Corporate Flight Bookings

There are n flights that are labeled from 1 to n.

You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] represents a booking for flights firsti through lasti (inclusive) with seatsi seats reserved for each flight in the range.

Return an array answer of length n, where answer[i] is the total number of seats reserved for flight i.

Example 1
Inputbookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5
Output[10,55,45,25,25]
The bookings reserve seats across flights 1 through 5, producing total seats [10, 55, 45, 25, 25].
Example 2
Inputbookings = [[1,2,10],[2,2,15]], n = 2
Output[10,25]
The bookings reserve 10 seats on flights 1 and 2 and 15 additional seats on flight 2, producing [10, 25].

Constraints

  • 1 <= n <= 2 * 10^4
  • 1 <= bookings.length <= 2 * 10^4
  • bookings[i].length == 3
  • 1 <= firsti <= lasti <= n
  • 1 <= seatsi <= 10^4

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate