MOENGAGE Off-Campus OA (2024) | Longest Continuous Subarray With Absolute Difference Less Than or Equal to Limit
Question · Posted Jun 2026
Problem Statement Given an integer array nums and an integer limit, return the length of the longest non-empty continuous subarray such that the absolute difference between any two elements in the subarray is less than or equal to limit. A subarray is a contiguous part of the array. Example Input: nums = [8,2,4,7] limit = 4 Output: 2 Explanation: Valid subarrays include: [8] [2] [4] [7] [2,4] [4,7] The longest valid subarray has length 2. Test Cases Test Case 1 ...
The full answer & interview discussion are available to premium members.
Log in Create a free account