#1359

Count All Valid Pickup and Delivery Options

expert · 1085 · lc hard +32 · verified · 64.9% accepted · 3,089 likes · top 69%

Description

You have n orders, each comprising a pickup and a delivery. Count all valid sequences of 2n events such that for every order i, its delivery occurs strictly after its pickup. Return the count modulo 109 + 7.

Example 1:

Input: n = 1
Output: 1
Explanation: Unique order (P1, D1), Delivery 1 always is after of Pickup 1.

Example 2:

Input: n = 2
Output: 6
Explanation: All possible orders:
(P1,P2,D1,D2), (P1,P2,D2,D1), (P1,D1,P2,D2), (P2,P1,D1,D2), (P2,P1,D2,D1) and (P2,D2,P1,D1).
This is an invalid order (P1,D2,P2,D1) because Pickup 2 is after of Delivery 2.

Example 3:

Input: n = 3
Output: 90

Code

1
2
3