Imagine, you have an array of integers of size N. At each index of this array is a unique integer fr…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
But in your nested loop, i will always be greater than j.
Your outer loop is starting i from 0. And your inner loop is starting j from i. While i is at any value, j will start from i and will be incremented until it is len(x).
This kind of approach will not work here. You will get TLE.
You have to a more efficient way to solve the problem.
You can learn counting inversions with merge sort after you have learnt merge sort.
To learn merge sort, see this.
To know how to count inversions using merge sort, see this
but i expect tle , everyone is getting ac with n sqaure, how is it possible at 1e5… i was cheking but my code got ac. i think test case is still weak . chk the shortest code
The shortest code would also get a WA now for the newly added test case. And if same bug in that code was corrected (which is also present in your code), then it would get a TLE for both of the last two cases.
But since that submission is from a contest, we won’t rejudge it.