
Count All Valid Pickup and Delivery Options (hard)
Problem Statement
You are given a positive integer n, representing total orders where each order consists of a pickup and a delivery service.
Count all valid pickup/delivery sequences such that delivery(x) is always after of pickup(x).
Return the answer modulo 10^9 + 7.
Examples
-
Example 1:
- Input:
n = 1 - Expected Output:
1 - Justification: With just one order, there's only one valid sequence: pickup and then delivery. Thus, the expected output is 1.
- Input:
-
Example 2:
- Input:
n = 2 - Expected Output:
6 - Justification: With two orders, there are six valid sequences: P1 D1 P2 D2, P1 P2 D1 D2, P1 P2 D2 D1, P2 D2 P1 D1, P2 P1 D1 D2, P2 P1 D2 D1. Therefore, the expected output is 6.
- Input:
-
Example 3:
- Input:
n = 5 - Expected Output:
113400 - Justification: For five orders, the number of valid sequences increases significantly because each additional order adds complexity to how pickups and deliveries can be arranged. The expected output for three orders is 113400.
- Input:
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory