PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Implement stream queries and bounded-difference subarrays

Last updated: May 24, 2026

Quick Overview

This question evaluates proficiency in data structures and algorithmic problem-solving, covering streaming uniqueness tracking (first-non-repeated element) and range-bounded contiguous subarray computation (max-min constraints).

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Implement stream queries and bounded-difference subarrays

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Solve both coding tasks. ### Task 1: Track the first non-repeated number in a stream Design a data structure that supports a stream of integers. Implement the following operations: - `FirstUnique(int[] nums)`: initializes the data structure with the given initial stream values, in order. - `int showFirstUnique()`: returns the first integer in insertion order that has appeared exactly once so far. If no such integer exists, return `-1`. - `void add(int value)`: appends `value` to the stream. Example: ```text Input: FirstUnique([2, 3, 5]) showFirstUnique() -> 2 add(5) showFirstUnique() -> 2 add(2) showFirstUnique() -> 3 add(3) showFirstUnique() -> -1 ``` Design the data structure so that each operation is efficient for a long stream. ### Task 2: Find the longest bounded-difference subarray Given an integer array `nums` and an integer `limit`, return the length of the longest contiguous subarray such that the absolute difference between any two elements in the subarray is less than or equal to `limit`. Equivalently, for a subarray `nums[l..r]`, it is valid if: ```text max(nums[l..r]) - min(nums[l..r]) <= limit ``` Example: ```text Input: nums = [8, 2, 4, 7], limit = 4 Output: 2 Explanation: The longest valid subarray is [2, 4]. ``` ```text Input: nums = [10, 1, 2, 4, 7, 2], limit = 5 Output: 4 Explanation: The longest valid subarray is [2, 4, 7, 2]. ```

Quick Answer: This question evaluates proficiency in data structures and algorithmic problem-solving, covering streaming uniqueness tracking (first-non-repeated element) and range-bounded contiguous subarray computation (max-min constraints).

Related Interview Questions

  • Thread-Safe Token-Bucket Rate Limiter - Uber (medium)
  • Group Anagrams - Uber (medium)
  • Quadtree for 2D Geospatial Points - Uber (medium)
  • Deep Equality of Two Records - Uber (medium)
  • Shortest Path in a Grid with Blocked Cells - Uber (medium)
|Home/Coding & Algorithms/Uber

Implement stream queries and bounded-difference subarrays

Uber logo
Uber
May 8, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
7
0
Practice Read
Loading...

Solve both coding tasks.

Task 1: Track the first non-repeated number in a stream

Design a data structure that supports a stream of integers.

Implement the following operations:

  • FirstUnique(int[] nums) : initializes the data structure with the given initial stream values, in order.
  • int showFirstUnique() : returns the first integer in insertion order that has appeared exactly once so far. If no such integer exists, return -1 .
  • void add(int value) : appends value to the stream.

Example:

Input:
FirstUnique([2, 3, 5])
showFirstUnique() -> 2
add(5)
showFirstUnique() -> 2
add(2)
showFirstUnique() -> 3
add(3)
showFirstUnique() -> -1

Design the data structure so that each operation is efficient for a long stream.

Task 2: Find the longest bounded-difference subarray

Given an integer array nums and an integer limit, return the length of the longest contiguous subarray such that the absolute difference between any two elements in the subarray is less than or equal to limit.

Equivalently, for a subarray nums[l..r], it is valid if:

max(nums[l..r]) - min(nums[l..r]) <= limit

Example:

Input: nums = [8, 2, 4, 7], limit = 4
Output: 2
Explanation: The longest valid subarray is [2, 4].
Input: nums = [10, 1, 2, 4, 7, 2], limit = 5
Output: 4
Explanation: The longest valid subarray is [2, 4, 7, 2].

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.