Search⌘ K
AI Features

Solution: Longest Strictly Increasing or Strictly Decreasing Suba

C# solution for the Longest Strictly Increasing or Strictly Decreasing Subarray problem using the Sliding Window pattern.

Statement

Given an integer array nums, find the maximum length of a contiguous subarray that is either strictly increasing or strictly decreasing.

A subarray is strictly increasing if for every adjacent pair of elements nums[i], nums[i+1] inside the subarray, nums[i] < nums[i+1].
A subarray is strictly decreasing if for every adjacent pair of elements nums[i], nums[i+1] inside the subarray, nums[i] > nums[i+1].

Return the length of the longest such subarray.

Constraints:

  • 11 \leq nums.length 50 ...