Back to problems

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

Algorithm · Tradedesk · Medium

You are given an array friendsList of integers and a positive integer minimumPairs. Your task is to count the number of contiguous subarrays (groups of adjacent friends) such that within the subarray, there are at least minimumPairs pairs of indices (i, j) with i < j and friendsList[i] == friendsList[j]. In other words, for each contiguous subarray, compute the number of equal-value pairs it contains. If that count is at least minimumPairs, the subarray qualifies. Return the…

Checking your access…