Tap here to switch tabs
Problem
Submissions

Problem: Monotonic Array

med
30 min
Try to solve the Monotonic Array problem.

Statement

bool isMonotonic(nums) returns true if the array nums is monotonic, and false otherwise.

An array is monotonic if it is either monotone increasing or monotone decreasing.

An array is monotone increasing if for every i such that 0 <= i < nums.length - 1, nums[i] <= nums[i + 1].

An array is monotone decreasing if for every i such that 0 <= i < nums.length - 1, nums[i] >= nums[i + 1].

Note: An array with one element is monotonic.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Monotonic Array

med
30 min
Try to solve the Monotonic Array problem.

Statement

bool isMonotonic(nums) returns true if the array nums is monotonic, and false otherwise.

An array is monotonic if it is either monotone increasing or monotone decreasing.

An array is monotone increasing if for every i such that 0 <= i < nums.length - 1, nums[i] <= nums[i + 1].

An array is monotone decreasing if for every i such that 0 <= i < nums.length - 1, nums[i] >= nums[i + 1].

Note: An array with one element is monotonic.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5