Count All Valid Pickup and Delivery Options

HardMathmath

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

There are n orders, and each order has a pickup event P_i and a delivery event D_i. A route is an ordering of all 2n events in which, for every order i, P_i comes before D_i. Return the number of valid routes modulo 10^9 + 7.

Examples

Input: n = 1
Output: 1
Only (P1, D1).
Input: n = 2
Output: 6
(P1,P2,D1,D2), (P1,P2,D2,D1), (P1,D1,P2,D2), (P2,P1,D1,D2), (P2,P1,D2,D1), (P2,D2,P1,D1).
Input: n = 3
Output: 90
The count grows quickly; for three orders it is 90.

Constraints

  • 1 <= n <= 500

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More math problems