Find counts and positions of elements that are out of order .
first , second = 0 , 0 NEW_LINE count = 0 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if arr [ i ] < arr [ i - 1 ] : NEW_LINE INDENT count += 1 NEW_LINE if first == 0 : NEW_LINE INDENT first = i NEW_LINE DEDENT else : NEW_LINE INDENT second = i NEW_LINE DEDENT DEDENT DEDENT