Skip to content

Commit c97f427

Browse files
committed
Solution as on 06-03-2022 07:45 am
2 parents eb698ca + 45a90aa commit c97f427

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// 1359.✅ Count All Valid Pickup and Delivery Options
2+
3+
class Solution
4+
{
5+
public:
6+
int countOrders(int n)
7+
{
8+
long res = 1, mod = 1000000007;
9+
for (int i = 1; i <= n; ++i)
10+
{
11+
// calulating n!
12+
res *= i;
13+
// to avoid overflow
14+
res %= mod;
15+
16+
// (2*i-1) are the vacant places which we can choose
17+
// later we have n! permutation of pickup task
18+
// therefore we have to multiply with n! that we calculated as res.
19+
res *= (2 * i - 1);
20+
21+
// to avoid overflow
22+
res %= mod;
23+
}
24+
25+
// to avoid overflow
26+
return res % mod;
27+
}
28+
};

0 commit comments

Comments
 (0)