Problem Β· Array

Tally the Number of Friend Groups with K Sets of Matching Traits 🐰

Learn this problem
● MediumTDTrade DeskOA

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) β†’ int

Examples

Example 1

friendList = [0, 1, 0, 1, 0]minimumPairs = 2return = 3

The 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 = 1

Only the full array contains six elements, which form three disjoint pairs of equal values.

Constraints

Unknown for now

More Trade Desk problems

drafts saved locally
public int tDeskFriendList(int[] friendList, int minimumPairs) {
    // write your code here
}
friendList[0, 1, 0, 1, 0]
minimumPairs2
expected3
checking account