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 ith 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.
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
Examples
01 · Example 1
arr = [1, 2, 1, 3, 4, 2, 4, 3, 3, 4] return = 8
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.
Constraints
1 ≤ n ≤ 104More Google problems
- Periodic Table Word FormationsPHONE SCREEN · Seen Jun 2026
- Split and Sort ArraySeen Jun 2026
- Fountain SafetyONSITE INTERVIEW · Seen Jun 2026
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
public int findConsistentLogs(int[] arr) {
// write your code here
}
arr[1, 2, 1, 3, 4, 2, 4, 3, 3, 4]
expected8
checking account