Tally the Number of Friend Groups with K Sets of Matching Traits 🐰
Updated
Problem statement
You are given an integer array friendList and a positive integer minimumPairs. Count the contiguous subarrays that contain at least minimumPairs disjoint pairs of equal values.
More formally, a qualifying subarray contains 2 * minimumPairs elements at pairwise distinct indices that can be grouped into minimumPairs pairs, with the two values in every pair equal. One array element cannot be used in more than one pair.
Return the number of qualifying contiguous subarrays.
Function
tDeskFriendList(friendList: int[], minimumPairs: int) → intExamples
Example 1
friendList = [0, 1, 0, 1, 0]minimumPairs = 2return = 3The qualifying subarrays are indices [0..3], [1..4], and [0..4]. Each contains two disjoint equal-value pairs.
Example 2
friendList = [2, 2, 2, 2, 2, 2]minimumPairs = 3return = 1Only the full array contains six elements, which form three disjoint pairs of equal values.
Constraints
Unknown for now
More The Trade Desk interview questions
Similar questions at other companies
- 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
- Longest Frequency-Bounded SubarrayZipRecruiter · OAZipRecruiter interview questions
- Find Subarray With Minimum Distinct IntegersAmazon · OA