FastPrepCount Subarrays with K Disjoint Equal Pairs
Problems/Count Subarrays with K Disjoint Equal Pairs

Count Subarrays with K Disjoint Equal Pairs

ZipRecruiter logoZipRecruiter● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter OA report describes the threshold for disjoint equal pairs, three numeric examples, and a sliding-window solution discussion. The employment label is not known, and the report leaves out a function signature, limits, and reusable image data. So our version uses the full-time default and supplies those details.

Given an integer array nums and a positive integer k, count contiguous subarrays that contain at least k pairwise disjoint pairs of equal values.

Each array occurrence may belong to at most one pair. Therefore, a subarray with frequencies freq[x] contains sum floor(freq[x] / 2) disjoint equal pairs.

Function

countSubarraysWithEqualPairs(nums: int[], k: int) → long

Examples

Example 1

nums = [1,1,2]k = 1return = 2

The qualifying subarrays are [1,1] and [1,1,2].

Example 2

nums = [1,1,1,1]k = 2return = 1

Only the full array contains two disjoint equal pairs.

Constraints

  • 1 <= nums.length <= 2 * 10^5.
  • 1 <= k <= nums.length / 2.
  • The answer fits in a 64-bit signed integer.

More ZipRecruiter Online Assessment questions

  • Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
  • Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
  • Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
  • Minimum Changes to Draw a YOA · Seen Oct 2024
  • Apply Binary State OperationsOA · Seen Sep 2024
  • Simulate Orchard Rot SpreadOA · Seen Sep 2024
  • Compare Odd- and Even-Index SumsOA · Seen Sep 2024
  • Coordinate Removals with Column GravityOA · Seen Sep 2024
  • Lexicographically Smallest End ReversalOA · Seen Sep 2024
  • Recursively Expanded Shell Command CountsOA · Seen Sep 2024

Similar questions at other companies

  • Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
  • Count Subarrays with at Least K Equal-Fruit PairsTikTok · OATikTok interview questions
  • Consistent LogsRippling · OARippling interview questions
  • Minimum Length Good SubarrayMicrosoft · OAMicrosoft interview questions
  • Auction Sniping Window MinimumCisco · OACisco interview questions
  • Balanced Prefix Sets in a PermutationUber · OAUber interview questions
  • Shortest Subarray Covering an Integer RangeMarshall Wace · OAMarshall Wace interview questions
  • Count Subarrays with at Least K Distinct ValuesVisa · OAVisa interview questions
  • Find Subarray With Minimum Distinct IntegersAmazon · OA

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public long countSubarraysWithEqualPairs(int[] nums, int k) {
      // write your code here
    }
}
Checking account…