• stuck in count inversion problem

Question related to mission Count Inversions


I think I am suppose count number of times series does not follow rule.

So I tried something like:

  def count_inversion(sequence):
  sequence = list(sequence)
  count = 0

  for i in sequence:
    if sequence[sequence.index(i)] - sequence[(sequence.index(i)-1)] != 1:

      count = (count + 1) 
  return count

But it is not giving me correct answer and I can't figure it out what is wrong!