K Inverse Pairs Array


@irajdeep It means that we are counting from the rightmost end OR we are shifting by the given amount towards the left.


@Todoloki for n=1 and k=1 answer is 0. And if we check k first then for n=0 and k=0 answer will be 1 but it should be 0.

@vinod23 Thank you. I realized where I am wrong. For n = 1, k can be in range [1, 1000], so we can not check the value of k first since invalid cases might exist and we need to deal with them properly.

@Greenbirdwei Thanks!
15243, 15324, 25134 all have four inversions. Here we are placing 5 in an array of n1 and k=1. I have updated the image. Please have a look. Thanks.


@LeonCheng It Should be dp[i][j]=count(i,j)+cum_sum, where cum_sum will be dp[i1][j]dp[i1][ji].