Count Derangements
Determine the number of derangements possible for a set of 'N' elements. A derangement is a permutation where no element appears in its original position.
Input:
An integer 'T' representing the number of test cases.
For each test case, an integer 'N' indicating the number of elements.
Output:
The total number of derangements for each test case modulo (10^9 + 7).
Example:
Input:
T = 2
N = 3
N = 4
Output:
2
9
Constraints:
- 1 <= T <= 100
- 1 <= N <= 3000
- Time limit: 1 sec
Note:
You don't need to output anything, simply implement the function specified.
ABHISHEK KUMAR SINGH
2y
https://www.geeksforgeeks.org/count-derangements-permutation-such-that-no-element-appears-in-its-original-position/
Help your peers!
Add answer anonymously...
Top Nagarro CSD interview questions & answers
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app