New update is available. Click here to update.

Last Updated: 16 Nov, 2020

Difficulty: Moderate

```
The answer could be very large, output answer %(10 ^ 9 + 7).
```

```
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line and the only line of each test case contains an integer ‘N’ denoting the number of elements whose derangements are to be counted.
```

```
For each test case, return the total number of derangements of a set of ‘N’ elements.
```

```
You don't need to print anything, it has been already taken care of. Just implement the given function.
```

```
1 <= T <= 100
1 <= N <= 3000
Time limit: 1 sec
```

SIMILAR PROBLEMS

DECODE STRING

Posted: 11 Sep, 2022

Difficulty: Moderate

Randomly Sorted

Posted: 13 Nov, 2022

Difficulty: Moderate

Merge Two Sorted Arrays Without Extra Space

Posted: 19 Nov, 2022

Difficulty: Moderate

Co-Prime

Posted: 14 Dec, 2022

Difficulty: Hard

8-Queen Problem

Posted: 19 Dec, 2022

Difficulty: Easy

Popular Interview Problems: