Count Subarrays with K Disjoint Equal Pairs
Updated
Problem statement
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) → longExamples
Example 1
nums = [1,1,2]k = 1return = 2The qualifying subarrays are [1,1] and [1,1,2].
Example 2
nums = [1,1,1,1]k = 2return = 1Only 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 Visa Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
Similar questions at other companies
- API Rate Limit Violation DetectionTekion · OATekion interview questions
- 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
- Longest Frequency-Bounded SubarrayZipRecruiter · OAZipRecruiter interview questions