1
# max absolte diff within a subarray is subarray max substracted by subarray min3
def longestSubarray(self, nums: List[int], limit: int) -> int:6
) # monotonic decreasing deque to compute subarray max, index of9
) # monotonic increasing deque to compute subarray min, index of13
for right in range(len(nums)):14
# pop monotocity-violating numbers from right end15
while q and nums[q[-1]] <= nums[right]:19
# pop monotocity-violating numbers from right end20
while q2 and nums[q2[-1]] >= nums[right]:25
while left < right and q and q2 and nums[q[0]] - nums[q2[0]] > limit:26
# compress window from left pointer27
if q and q[0] == left:30
# compress left pointer31
if q2 and q2[0] == left:36
if nums[q[0]] - nums[q2[0]] <= limit:37
res = max(res, right - left + 1)