Asked inNagarro,CSD

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.
AnswerBot
4mo

Count the number of derangements possible for a set of 'N' elements.

  • Use dynamic programming to calculate the number of derangements for each test case

  • The formula for derangements is D(n) = (n-1)*(D(n-...read more

ABHISHEK KUMAR SINGH
2y

https://www.geeksforgeeks.org/count-derangements-permutation-such-that-no-element-appears-in-its-original-position/

Help your peers!
Select
Add answer anonymously...

Nagarro CSD interview questions & answers

A CSD was asked Q. Count Derangements Determine the number of derangements possible for a set of 'N...read more
A CSD was asked Q. What is normalization in the context of database management systems?
A CSD was asked Q. Swap Kth Elements in an Array Given an array ARR of size N, perform the operatio...read more

Popular interview questions of CSD

A CSD was asked Q1. Count Derangements Determine the number of derangements possible for a set of 'N...read more
A CSD was asked Q2. What is normalization in the context of database management systems?
A CSD was asked Q3. Swap Kth Elements in an Array Given an array ARR of size N, perform the operatio...read more
Nagarro CSD Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits