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 𓆝⋆。˚ 𓇼°
userEvent = [1, 2, 1, 3, 4, 2, 4, 3, 3, 4] return = 8
1 <= n <= 3 * 1051 <= userEvent[i] <= 109
- Minimum Path Sum to Target in Binary TreePHONE SCREEN · Seen Apr 2026
- Social Media SuggestionsSeen May 2025
- Best Sum Downward Tree PathSeen May 2025
- Price CheckSeen Feb 2025
- Palindromic Substrings (LC 647 :)Seen Jan 2025
- Get Distinct Goodness ValuesSeen Jan 2025
- Get Min OperationsSeen Jan 2025
- Count Stable SegmentsSeen Jan 2025
public int findConsistentLogs(int[] userEvent) {
// write your code here :)
}