Longest Continuous Subarray Within an Absolute-Difference Limit
Updated
Problem statement
Given an integer array and a nonnegative limit, return the maximum length of a nonempty contiguous subarray whose maximum and minimum values differ by at most limit. Return 0 for an empty array.
Function
longestSubarrayWithinLimit(nums: int[], limit: int) → intExamples
Example 1
nums = [8,2,4,7]limit = 4return = 2The longest valid window has length two.
Example 2
nums = [10,1,2,4,7,2]limit = 5return = 4The window [2,4,7,2] has range five.
Example 3
nums = [4,2,2,2,4,4,2,2]limit = 0return = 3The longest constant run has length three.
Constraints
0 <= nums.length <= 100000.0 <= limit <= 10^9.
Source note: Author-written prompt excerpt retained for source fidelity.
More Uber Onsite Interview questions
- Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Online Meeting Scheduler with Fixed RoomsONSITE INTERVIEW · Seen Oct 2026
- Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Serialize and Deserialize an N-Ary TreeONSITE INTERVIEW · Seen Oct 2026
- K Smallest Squares from a Sorted ArrayONSITE INTERVIEW · Seen Sep 2026
- Grid Robot Route with Charging PrioritiesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Shortest Increasing Path to a TargetONSITE INTERVIEW · Seen Sep 2026
- My Calendar IONSITE INTERVIEW · Seen Sep 2026
- Per-Element Hit CounterONSITE INTERVIEW · Seen Sep 2026
- Cheapest Round TripONSITE INTERVIEW · Seen Aug 2026
Similar questions at other companies
- Longest Subarray Within an Absolute-Difference LimitGoogle · ONSITE INTERVIEWGoogle interview questions
- Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
- Bad Request AlertsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Sliding Window MaximumAmazon · ONSITE INTERVIEW
- Fixed-Window Rolling MeanJump Trading · ONSITE INTERVIEWJump Trading interview questions
- Sliding Window MaximumPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Sliding Window MaximumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Sliding Window Average (Meta Canada, E4/E5 :)Meta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Disk Space Window AnalyzerAgoda · PHONE SCREENAgoda interview questions
- Longest Continuous Subarray Within an Absolute-Difference LimitOracle · PHONE SCREENOracle interview questions