Search topics...

Monotonic Array

easy
arrayTime: O(n)Space: O(1)Frequency: 3

Given an array, return true if it is monotone increasing or monotone decreasing.

Example 1:

Input: nums = [1, 2, 2, 3]
Output: true
Explanation: The array is monotone increasing.

Example 2:

Input: nums = [6, 5, 4, 4]
Output: true
Explanation: The array is monotone decreasing.

Example 3:

Input: nums = [1, 3, 2]
Output: false