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.

&nbsp;
Example 1:

Input: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5
Output: [10,55,45,25,25]
Explanation:
Flight labels:        1   2   3   4   5
Booking 1 reserved:  10  10
Booking 2 reserved:      20  20
Booking 3 reserved:      25  25  25  25
Total seats:         10  55  45  25  25
Hence, answer = [10,55,45,25,25]


Example 2:

Input: bookings = [[1,2,10],[2,2,15]], n = 2
Output: [10,25]
Explanation:
Flight labels:        1   2
Booking 1 reserved:  10  10
Booking 2 reserved:      15
Total seats:         10  25
Hence, answer = [10,25]



&nbsp;
Constraints:


	1 &lt;= n &lt;= 2 * 104
	1 &lt;= bookings.length &lt;= 2 * 104
	bookings[i].length == 3
	1 &lt;= firsti &lt;= lasti &lt;= n
	1 &lt;= seatsi &lt;= 104


class Solution:
	def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:

		flights = [0]*n
		for start,end,seats in bookings:
			flights[start-1] += seats
			if end < n: flights[end] -= seats
		for i in range(n-1):
			flights[i+1] += flights[i]
		return flights
class Solution {
    public int[] corpFlightBookings(int[][] bookings, int n) {
        // nums all equals to zero
        int[] nums = new int[n];
        // construct the diffs
        Difference df = new Difference(nums);

        for (int[] booking : bookings) {
            // pay attention to the index
            int i = booking[0] - 1;
            int j = booking[1] - 1;
            int val = booking[2];
            // increase nums[i..j] by val
            df.increment(i, j, val);
        }
        // return the final array
        return df.result();
    }

    class Difference {
        // diff array
        private int[] diff;

        public Difference(int[] nums) {
            assert nums.length > 0;
            diff = new int[nums.length];
            // construct the diffs
            diff[0] = nums[0];
            for (int i = 1; i < nums.length; i++) {
                diff[i] = nums[i] - nums[i - 1];
            }
        }

        // increase nums[i..j] by val
        public void increment(int i, int j, int val) {
            diff[i] += val;
            if (j + 1 < diff.length) {
                diff[j + 1] -= val;
            }
        }

        public int[] result() {
            int[] res = new int[diff.length];
            // contract the diff array based on the result
            res[0] = diff[0];
            for (int i = 1; i < diff.length; i++) {
                res[i] = res[i - 1] + diff[i];
            }
            return res;
        }
    }

}
class Solution {
public:
    vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n) {
        vector<int> arr(n);
        for (const auto& b : bookings) {
            int start = b[0] - 1, end = b[1], seats = b[2];
            arr[start] += seats;
            if (end < n) {
                arr[end] -= seats;
            }
        }
        partial_sum(begin(arr), end(arr), begin(arr));
        return arr;
    }
};
var corpFlightBookings = function(bookings, n) {
    
    // +1 as dummy guard on the tail, which allow us not to check right boundary every time
    let unitStep = Array(n+1).fill(0);
    
    for(const [first, last, seatVector ] of bookings ){
        
        // -1 because booking flight is 1-indexed, given by description
        let [left, right] = [first-1, last-1];
        
        unitStep[ left ] += seatVector;
        unitStep[ right+1 ] -= seatVector;
    }
    
    // Reconstruct booking as drawing combination of retangle signal, built with unit step impulse
    for( let i = 1; i < unitStep.length ; i++ ){
        unitStep[ i ] += unitStep[ i-1 ];
    }
    
    
    // last one is dummy guard on the tail, no need to return
    return unitStep.slice(0, n);
};
Corporate Flight Bookings