Flight seat reservations

Write codeMedium18 min

Your task

There are n flights labelled 1 to n. You are given bookings where bookings[i] = [first, last, seats] meaning seats seats were reserved on every flight from first to last inclusive. Return an array of length n where the i-th element is the total seats reserved on flight i+1. With up to 210^4 bookings and n up to 210^4, apply each booking as an O(1) range update on a difference array and take a prefix sum at the end.

Examples

corp_flight_bookings(bookings: list[list[int]], n: int) -> list[int]
Example 1
Inputcorp_flight_bookings([[1, 2, 10], [2, 3, 20], [2, 5, 25]], 5)
Output[10, 55, 45, 25, 25]