Number of permutation with K inversions
Easy Accuracy: 4.54% Submissions: 22 Points: 2

Given an array, an inversion is defined as a pair a[i], a[j] such that a[i] > a[j] and i < j. Given two numbers N and K, the task is to find the count of the number of permutations of first N numbers have exactly K inversion.

Note: Answer can be large, output answer modulo 109 + 7

Example 1:

Input: N = 3, K = 1
Output: 2
Explanation: Total Permutation of first 
3 numbers, 123, 132, 213, 231, 312, 321
Permutation with 1 inversion : 132 and 213
Example 2:
Input: N = 3, K = 3
Output: 0
Explanation: No such permutation

Your Task:  
You don't need to read input or print anything. Complete the function numberOfPermWithKInversion() which takes N and K as input parameters and returns the integer value

Expected Time Complexity: O(N*K)
Expected Auxiliary Space: O(N*K)

1 ≤ N*K ≤ 106


to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.