Problem Β· Array
Tally the Number of Friend Groups with K Sets of Matching Traits π°
Learn this problemProblem 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