Light Mode
Dark Mode
Test 5 Issue

My code is successful on the first 4 tests but gets 2635 for test 5 instead of 4181 on the 5th test. Help is greatly appreciated!

def count_inversion(sequence):
    """
        Count inversions in a sequence of numbers
    """
    length = len(sequence)
    count, x, y = 0, 0, 1
    while y < length:
        if sequence[x] > sequence[y]:
            z = y + 1
            count += 1
            while z < length:
                if sequence[x] > sequence[z]:
                    count += 1
                z += 1
        x += 1
        y += 1
    print('Final count =', count)
    return count
Created: May 7, 2016, 6:42 p.m.
Updated: May 8, 2016, 5:45 a.m.
0
4
User avatar
gasvom