One Direction Sequence

Sometimes you need to check whether a sequence keeps moving in one direction. Given a list nums, return True if it is entirely non-decreasing or entirely non-increasing. Equal neighboring elements do not break monotonicity. If the direction changes from increasing to decreasing or back, return False.

Примеры

Ввод
[1, 2, 2, 3]
Вывод
True
Ввод
[6, 5, 4, 4]
Вывод
True
Ввод
[1, 3, 2]
Вывод
False

Нужно реализовать

def is_monotonic(nums: list[int]) -> bool:

Теги

array
PostgreSQLv16

Your code output will appear here

Visible tests
1
Input
[1,2,2,3]
ExpectedTrue
2
Input
[6,5,4,4]
ExpectedTrue
3
Input
[1,3,2]
ExpectedFalse
4
Input
[1,2,3,4,5,6,5]
ExpectedFalse
5
Input
[-3,-2,-1]
ExpectedTrue
6
Input
[-5,-6,-7]
ExpectedTrue
Focus radio
Paused · SomaFM · Fluid