PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Uber

Count subarrays with at least k fruit pairs

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving focused on frequency-based counting and efficient enumeration of subarrays, testing competence in designing subquadratic solutions and selecting appropriate data representations within the Coding & Algorithms domain.

  • Medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Count subarrays with at least k fruit pairs

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

Given an integer array nums where each value denotes a fruit type, and an integer k: For any subarray, define a 'pair' for fruit value v if its frequency in the subarray is at least 2; each fruit contributes at most one pair regardless of appearing more than twice. Return the number of subarrays whose number of such pairs is at least k. Example: nums = [0, 1, 0, 1, 0], k = 2 → 3 (valid subarrays are [0, 1, 0, 1], [1, 0, 1, 0], and [0, 1, 0, 1, 0]). Design an algorithm better than O(n^ 2), explain your approach (e.g., sliding window or two pointers), and analyze complexity.

Quick Answer: This question evaluates algorithmic problem-solving focused on frequency-based counting and efficient enumeration of subarrays, testing competence in designing subquadratic solutions and selecting appropriate data representations within the Coding & Algorithms domain.

Related Interview Questions

  • Implement stream queries and bounded-difference subarrays - Uber (medium)
  • Implement Minesweeper and Word Search - Uber (medium)
  • Implement Store Autocomplete - Uber (medium)
  • Simulate a Rank-Based Tournament - Uber (medium)
  • Implement Cache Eviction And Seat Assignment - Uber (medium)
Uber logo
Uber
Sep 6, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
6
0

Given an integer array nums where each value denotes a fruit type, and an integer k: For any subarray, define a 'pair' for fruit value v if its frequency in the subarray is at least 2; each fruit contributes at most one pair regardless of appearing more than twice. Return the number of subarrays whose number of such pairs is at least k. Example: nums = [0, 1, 0, 1, 0], k = 2 → 3 (valid subarrays are [0, 1, 0, 1], [1, 0, 1, 0], and [0, 1, 0, 1, 0]). Design an algorithm better than O(n^ 2), explain your approach (e.g., sliding window or two pointers), and analyze complexity.

Comments (0)

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 7,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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.