>>81458069

Yes, you can group the values into sublists such that the first element of the sublist is bigger than the next values of the list, then reduce to length, and if the list is all 1s it means it is perfectly sorted, if it is one 2 and the rest is 1s it means that there is only one out of order, and anything else is more than one out of order. I'll show it to you in Haskell:

Prelude Data.List> groupBy (\x y-> x > y) [1,6,7,2,3]

[[1],[6],[7,2,3]]

Prelude Data.List> map length $ groupBy (\x y-> x > y) [1,6,7,2,3]

[1,1,3]

Prelude Data.List> foldl (\(a,b,c) x -> if x == 1 then (a+1,b,c) else if x == 2 then (a,b+1,c) else (a,b,c+1)) (0,0,0) $ map length $ groupBy (\x y-> x > y) [1,6,7,2,3]

(2,0,1)

I know it is a bit ugly as a one-liner , but that 3-tuple basically means "if there is (x,1,0) there is one out of order, (x,0,0) all in order and anything else is more than one out of order)