FastPrepLongest Continuous Subarray Within an Absolute-Difference Limit
Problems/Longest Continuous Subarray Within an Absolute-Difference Limit

Longest Continuous Subarray Within an Absolute-Difference Limit

Uber logoUber● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a well-known task. We chose the function signature, a fixed order for the output, and the input limits. Our version is about 98% the same as the reported question.

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) → int

Examples

Example 1

nums = [8,2,4,7]limit = 4return = 2

The longest valid window has length two.

Example 2

nums = [10,1,2,4,7,2]limit = 5return = 4

The window [2,4,7,2] has range five.

Example 3

nums = [4,2,2,2,4,4,2,2]limit = 0return = 3

The 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
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int longestSubarrayWithinLimit(int[] nums, int limit) {
        // write your code here
    }
}
Checking account…