Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MOD = 10 ** 9 + 7
- class Solution:
- def countOrders(self, n: int) -> int:
- # Answer is (2n)! / 2^n
- # as we can consider all the distinct shufflings of the array [1, 1, 2, 2, ..., n, n]
- # The first occurrence of a number is it's pickup, the second is it's drop-off
- # Calculating this number modulu MOD, is annoying, but we can simplify this into
- # n! * (1 * 3 * ... * (2n - 1)) % MOD
- return functools.reduce(
- lambda a, b: (a * b) % MOD,
- itertools.chain(range(1, n + 1), range(1, 2 * n, 2)),
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement