Find Consistent Logs
The developers working on a social media network app want to analyze user behavior. There are n event logs where userEvent[i] denotes the userId for the user that triggered the ith event. The team wants to analyze the subarray of the logs which are consistent, that is, the frequency of the most frequent user in the subarray is equal to the frequency of the least frequent user in the whole array. Find the maximum length of consistent logs.
Note: A subarray is a contiguous group of elements in an array.
Complete the function findConsistentLogs in the editor 👉👉.
findConsistentLogs has the following parameters:
int userEvent[n]: the userIds present in the event logs
Returns
int: the maximum length of consistent logs
𓇢𓆸, Credit to 𓇼 ⋆。˚Rachel 𓆝⋆。˚ 𓇼°
1Example 1
Constraints
Limits and guarantees your solution can rely on.
1 <= n <= 3 * 1051 <= userEvent[i] <= 109