Count All Valid Pickup and Delivery Options
HardLeetCodeCombinatorics & Modular Arithmetic
Approach hintTry it first, then revealHide
Add orders one at a time. With 2(i - 1) items already placed, the new pickup and delivery occupy two of 2i positions with pickup first, giving i * (2i - 1) ways; multiply the factors modulo 1e9+7.