Grokking the Coding Interview: Patterns for Coding Questions
0% completed
Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit (medium)
Problem Statement
Given an integer array nums and an integer limit, return the maximum length of a continuous subarray such that the absolute difference between any two elements in this subarray is less than or equal to limit. The subarray must be non-empty.
Examples
Example 1:
- Input: nums = [1, 3, 6, 7, 9, 10], limit = 3
- Output: 3
- Explanation: Consider the
[6, 7, 9]or[7, 9, 10]array. The absolute difference between any two elements in these subarrays is at most 3.
Example 2:
- Input: nums = [8, 2, 4, 10, 12], limit = 6
.....
.....
.....
Like the course? Get enrolled and start learning!