count inversions algorithm returning correct result and has passed tests