Ctrl K

Parcel Run Orders

Hard
A courier has parcels parcels to handle. Each parcel involves two events: the courier **picks it up** and later **drops it off**. All 2 · parcels events form one sequence. A sequence is valid if every parcel is dropped off after it has been picked up. Count the valid sequences. The answer can be large, so return it modulo 10⁹ + 7.
Example 1
parcels=1 → 1

The only option is to pick the parcel up and then drop it off.

Example 2
parcels=2 → 6

Write P for a pick-up and D for a drop-off. The valid orders are 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, 6 in total. P1 D2 P2 D1, for example, does not count: parcel 2 is dropped off before it is picked up.

Example 3
parcels=4 → 2520
Constraints
  • 1 ≤ parcels ≤ 500
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTasters and the Spoiled Cask HardRadio Show Without Quick Repeats HardA Fair Split of Colored Beads HardOther Orders for the Same Search Tree HardK-th Route in Alphabetical Order Hard
loading Python…
Input
parcels=1
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 35 tests on the server, hidden ones included.