LeetCode solutions

1461. Count All Valid Pickup and Delivery Options

My accepted Python solution to LeetCode problem 1461, Count All Valid Pickup and Delivery Options, running in 0ms.

  • Difficulty: Hard
  • Python
  • Runtime 0ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2026-01-02.

python
class Solution:
    def countOrders(self, n: int) -> int:
        MOD = 10**9 + 7
        result = 1
        for i in range(1, n + 1):
            result = result * i * (2 * i - 1) % MOD
        return result

Source