Count All Valid Pickup and Delivery Options

Given n orders, each order consists of a pickup and a delivery service.

Count all valid pickup/delivery possible sequences such that delivery(i) is always after pickup(i).

Since the answer may be too large, return it modulo 10^9 + 7.

Example 1
Inputn = 1
Output1
Unique order (P1, D1), so Delivery 1 is always after Pickup 1.
Example 2
Inputn = 2
Output6
There are 6 valid orders; (P1, D2, P2, D1) is invalid because Pickup 2 is after Delivery 2.

Constraints

  • 1 <= n <= 500

Asked at 3 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate