JuniorArray

Longest Strictly Increasing or Strictly Decreasing Subarray

You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing.

Example 1
Inputnums = [1,4,3,3,2]
Output2
The longest strictly increasing or strictly decreasing subarrays have length 2, such as [1,4], [4,3], or [3,2].
Example 2
Inputnums = [3,3,3,3]
Output1
All elements are equal, so only single-element subarrays are strictly increasing or strictly decreasing.

Constraints

  • 1 <= nums.length <= 50
  • 1 <= nums[i] <= 50

Asked at 7 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate