Advertisement
DakshJain

Count Inversions

Sep 2nd, 2023
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. import java.util.* ;
  2. import java.io.*;
  3. public class Solution {
  4. public static long getInversions(long arr[], int n) {
  5. // Write your code here.
  6. long ans=0;
  7. for(int i=0; i<n; i++){
  8. for(int j=i+1;j<n;j++){
  9. if(arr[i] > arr[j]){
  10. ans++;
  11. }
  12. }
  13. }
  14. return ans;
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement