pyassistant

Longest subarray where max - min <= limit

Given an array of integers nums and an integer limit, find the length of the longest contiguous subarray such that the difference between the maximum and minimum elements in that subarray is less than or equal to limit.

Example:

Input:
nums = [8, 2, 4, 7], limit = 4
Output:
2

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.