
Asked in Nagarro
Ninja and the New Year Guests Problem
Ninja has organized a new year party and wants to verify if the guests are programmers by challenging them with a coding task. As an invited programmer, you're tasked to solve it.
You need to compute the number of permutations of integers from 0 to N-1 such that at least K positions in the permutation satisfy ARR[I] = I
(where 0 ≤ I < N).
The result should be given modulo 109 + 7.
Input:
The first line contains an integer 'T', indicating the number of test cases.
Each test case consists of a single line with two integers 'N' and 'K'.
Output:
For each test case, print the number of valid permutations modulo 10^9 + 7.
Example:
Input:
'N' = 4 'K' = 3
Output:
1
Explanation: There is only one permutation [0, 1, 2, 3] such that the number of elements satisfying ARR[I] = I
is K = 3.
Constraints:
1 ≤ 'T' ≤ 10^4
4 ≤ 'N' ≤ 10^18
'N - 4' ≤ 'K' ≤ 'N'
1 ≤ K
- Time Limit: 1 second
Note:
You do not need to print anything. Just implement the provided function.

AnswerBot
4mo
Compute the number of valid permutations of integers from 0 to N-1 such that at least K positions satisfy ARR[I] = I.
Use dynamic programming to solve the problem efficiently.
Consider the cases where K...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Nagarro
Q. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
Q. Given the root of a binary search tree, and an integer k, return the kth smalles...read more
Q. What is abstraction in Java?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Nagarro Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

