Tap here to switch tabs
Problem
Ask
Submissions

Problem: Longest Subarray With Diff At Most Limit

med
30 min
Explore how to apply the sliding window approach to identify the longest subarray in an integer array where the absolute difference between any two elements does not exceed a specified limit. Understand problem constraints and develop an efficient solution that balances window size and element differences.

Statement

Given an integer array nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements within that subarray is less than or equal to limit.

Constraints:

  • 11 \leq nums.length 105\leq 10^5

  • 11 \leq nums[i] 109\leq 10^9

  • 00 \leq limit 109\leq 10^9

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Longest Subarray With Diff At Most Limit

med
30 min
Explore how to apply the sliding window approach to identify the longest subarray in an integer array where the absolute difference between any two elements does not exceed a specified limit. Understand problem constraints and develop an efficient solution that balances window size and element differences.

Statement

Given an integer array nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements within that subarray is less than or equal to limit.

Constraints:

  • 11 \leq nums.length 105\leq 10^5

  • 11 \leq nums[i] 109\leq 10^9

  • 00 \leq limit 109\leq 10^9