Monotonic Array Lab

Easy
19
63.5% Acceptance

In this lab, you will be working with monotonic arrays. An array is considered monotonic if it is either monotone increasing or monotone decreasing. Monotone increasing means that for all i <= j, nums[i] <= nums[j]. Monotone decreasing means that for all i <= j, nums[i] >= nums[j]. Your task is to create a function that takes an integer array nums and returns true if the given array is monotonic, and false otherwise.

To help you better understand the problem, consider the following examples:

isMonotonic([1, 2, 2, 3]) // true isMonotonic([6, 5, 4, 4]) // true isMonotonic([1, 3, 2]) // false

Challenges

  1. Export the isMonotonic function from your index.js file.
  2. Implement the isMonotonic function to correctly identify monotonic arrays based on the given constraints:
    • 1 <= nums.length <= 10^5
    • -10^5 <= nums[i] <= 10^5
  3. Make sure your export the function