1109. Corporate Flight Bookings Medium

@problem@discussion
#Array#Prefix Sum



1/**
2 * [1109] Corporate Flight Bookings
3 *
4 * There are n flights that are labeled from 1 to n.
5 * 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.
6 * Return an array answer of length n, where answer[i] is the total number of seats reserved for flight i.
7 *  
8 * Example 1:
9 * 
10 * Input: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5
11 * Output: [10,55,45,25,25]
12 * Explanation:
13 * Flight labels:        1   2   3   4   5
14 * Booking 1 reserved:  10  10
15 * Booking 2 reserved:      20  20
16 * Booking 3 reserved:      25  25  25  25
17 * Total seats:         10  55  45  25  25
18 * Hence, answer = [10,55,45,25,25]
19 * 
20 * Example 2:
21 * 
22 * Input: bookings = [[1,2,10],[2,2,15]], n = 2
23 * Output: [10,25]
24 * Explanation:
25 * Flight labels:        1   2
26 * Booking 1 reserved:  10  10
27 * Booking 2 reserved:      15
28 * Total seats:         10  25
29 * Hence, answer = [10,25]
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	1 <= n <= 2 * 10^4
35 * 	1 <= bookings.length <= 2 * 10^4
36 * 	bookings[i].length == 3
37 * 	1 <= firsti <= lasti <= n
38 * 	1 <= seatsi <= 10^4
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/corporate-flight-bookings/
44// discuss: https://leetcode.com/problems/corporate-flight-bookings/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn corp_flight_bookings(bookings: Vec<Vec<i32>>, n: i32) -> Vec<i32> {
50        vec![]
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_1109() {
62    }
63}
64


Back
© 2025 bowen.ge All Rights Reserved.