Add to every flight
Time O(n · b) Space O(n)For each booking, loop from first to last adding seats.
class Solution {
public int[] corpFlightBookings(int[][] bookings, int n) {
int[] out = new int[n];
for (int[] b : bookings)
for (int f = b[0]; f <= b[1]; f++) out[f - 1] += b[2];
return out;
}
}Verdict: 4 × 10⁸ steps in the worst case: too slow.