Count All Valid Pickup and Delivery Options LeetCode solution in JavaScript

1
var countOrders = function (n) {
2
let ans = 1; //for n=1, there will only be one valid pickup and delivery
3
for (let i = 2; i <= n; i++) {
4
let validSlots = 2 * i - 1; //calculating number of valid slots of new pickup in (n-1)th order
5
validSlots = (validSlots * (validSlots + 1)) / 2;
6
ans = (ans * validSlots) % 1000000007; //multiplying the ans of (n-1)th order to current order's valid slots
7
}
8
return ans;
9
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0