Method 1: Calculate inversions

Loop