Count Inversions

BRUTE FORCE
 avatar
unknown
java
7 days ago
348 B
3
Indexable
import java.util.* ;
import java.io.*; 
public class Solution {
    public static long getInversions(long arr[], int n) {
        int i, j, c = 0;
        for(i=0;i<n;++i)
        {
            for(j=i+1;j<n;++j)
            {
                if(arr[i]>arr[j])
                c++;
            }
        }

        return c;
    }
}
Leave a Comment