1
2
3
4
import Data.List

check (x:xs) = (all (< x) xs || all (> x) xs) && check xs
check []     = True