Leetcode Problem 2863. Maximum Length of Semi-Decreasing Subarrays
2863. Maximum Length of Semi-Decreasing Subarrays
Leetcode Solutions
Stack-based Approach for Longest Semi-Decreasing Subarray
Initialize an empty stack to store indices of potential end points.
Iterate over the array from the end to the beginning.
For each element, if the stack is empty or the current element is less than the element at the top of the stack, push the current index onto the stack.
Initialize a variable to keep track of the maximum length found so far.
Iterate over the array from the beginning.
For each element, while the stack is not empty and the current element is greater than the element at the index at the top of the stack, update the maximum length and pop the top of the stack.