Count All Valid Pickup and Delivery Options LeetCode solution in JavaScript
1var countOrders = function (n) {2let ans = 1; //for n=1, there will only be one valid pickup and delivery3for (let i = 2; i <= n; i++) {4let validSlots = 2 * i - 1; //calculating number of valid slots of new pickup in (n-1)th order5validSlots = (validSlots * (validSlots + 1)) / 2;6ans = (ans * validSlots) % 1000000007; //multiplying the ans of (n-1)th order to current order's valid slots7}8return ans;9};