The organizers of a gaming tournament want to analyze player participation based on event logs. There are n
event logs, where arr[i]
indicates the playerId of the player who participated in the i
th event. The organizers need to identify subarrays of these logs that are consistent, meaning that the frequency of the most frequent player in the subarray matches the frequency of the least frequent player in the entire array. Determine the maximum length of such consistent logs.
Function Description
Complete the function findConsistentLogs
with the following parameters:
int arr[n]
: the playerIds present in the event logs
Returns
int: the maximum length of the consistent logs
Example 1:
Input: arr = [1, 2, 1, 3, 4, 2, 4, 3, 3, 4]
Output: 8
Explanation:Given:n = 10 arr = [1, 2, 1, 3, 4, 2, 4, 3, 3, 4] The frequencies of playerIds 1 and 2 are 2. The frequencies of playerIds 3 and 4 are 3. The minimum frequency in the array is 2. The longest valid subarray with this property is [1, 2, 1, 3, 4, 2, 4, 3], which has 8 elements. In this subarray, the most common element appears 2 times, which matches the minimum frequency in the entire array. Therefore, the maximum length of consistent logs is 8.
1 ≤ n ≤ 104

input:
output: