Skip to content

Commit 5cc668d

Browse files
committed
Add solution #1109
1 parent 08b438a commit 5cc668d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,138 LeetCode solutions in JavaScript
1+
# 1,139 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -882,6 +882,7 @@
882882
1105|[Filling Bookcase Shelves](./solutions/1105-filling-bookcase-shelves.js)|Medium|
883883
1106|[Parsing A Boolean Expression](./solutions/1106-parsing-a-boolean-expression.js)|Hard|
884884
1108|[Defanging an IP Address](./solutions/1108-defanging-an-ip-address.js)|Easy|
885+
1109|[Corporate Flight Bookings](./solutions/1109-corporate-flight-bookings.js)|Medium|
885886
1122|[Relative Sort Array](./solutions/1122-relative-sort-array.js)|Easy|
886887
1123|[Lowest Common Ancestor of Deepest Leaves](./solutions/1123-lowest-common-ancestor-of-deepest-leaves.js)|Medium|
887888
1137|[N-th Tribonacci Number](./solutions/1137-n-th-tribonacci-number.js)|Easy|
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* 1109. Corporate Flight Bookings
3+
* https://leetcode.com/problems/corporate-flight-bookings/
4+
* Difficulty: Medium
5+
*
6+
* There are n flights that are labeled from 1 to n.
7+
*
8+
* You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi]
9+
* represents a booking for flights firsti through lasti (inclusive) with seatsi seats reserved
10+
* for each flight in the range.
11+
*
12+
* Return an array answer of length n, where answer[i] is the total number of seats reserved for
13+
* flight i.
14+
*/
15+
16+
/**
17+
* @param {number[][]} bookings
18+
* @param {number} n
19+
* @return {number[]}
20+
*/
21+
var corpFlightBookings = function(bookings, n) {
22+
const result = new Array(n).fill(0);
23+
24+
for (const [start, end, count] of bookings) {
25+
result[start - 1] += count;
26+
if (end < n) result[end] -= count;
27+
}
28+
29+
for (let i = 1; i < n; i++) {
30+
result[i] += result[i - 1];
31+
}
32+
33+
return result;
34+
};

0 commit comments

Comments
 (0)