res
of length n + 1
with all zeros.bookings
array.
a. For each booking [first, last, seats]
, increment res[first - 1]
by seats
(add seats at the start of the range).
b. Decrement res[last]
by seats
(remove seats after the end of the range).res
array.
a. Iterate from the second element to the last element of the res
array.
b. Update each element by adding it to the previous element's value.res
array as it is not needed (it represents the seats after the last flight).res
array as the result.