LeetCode 1359. Count All Valid Pickup and Delivery Options
Question
Given n
orders, each order consist in pickup and delivery services.
Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i).
Since the answer may be too large, return it modulo 10^9 + 7.
Example
1 | Input: n = 1 |
Solution
We assumed it already have n - 1
pair, and we have to place the final pair. The number of we can place is 2 * (n - 1) + 1 = 2*n - 1
, so for the last, it should be 2 * n
, which add one more section we can use due to the operation.
Code
1 | // time:O(n), space:O(1) |