1
var corpFlightBookings = function (bookings, n) {2
// +1 as dummy guard on the tail, which allow us not to check right boundary every time3
let unitStep = Array(n + 1).fill(0);5
for (const [first, last, seatVector] of bookings) {6
// -1 because booking flight is 1-indexed, given by description7
let [left, right] = [first - 1, last - 1];9
unitStep[left] += seatVector;10
unitStep[right + 1] -= seatVector;13
// Reconstruct booking as drawing combination of retangle signal, built with unit step impulse14
for (let i = 1; i < unitStep.length; i++) {15
unitStep[i] += unitStep[i - 1];18
// last one is dummy guard on the tail, no need to return19
return unitStep.slice(0, n);