Question: The developers working on a social media network app want to analyze user behavior. TheruserEventlint logs where userEvent / i ] denotes the userld for

The developers working on a social media network app want to analyze user behavior. TheruserEventlint logs where userEvent/i] denotes the userld for the user that triggered the ith event. The team wants to analyze the subarrays 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.
Example
4]
Given n =10, and userEvent =[1,2,1,3,4,2,4,3,3,
The frequencies of 1 and 2 are 2.
The frequencies of 3 and 4 are 3.
The minimum frequency in the array is 2.
The longest valid subarray has 8 elements: [1,2,1,3,4,2,4,31.
The frequencies of 1,2,3, and 4 are all 2.
The frequency of the most common element in the subarray is 2, the same as the minimum frequency in the entire array.
Hence, the maximum length of consistent logs is 8.
Function Description
Complete the function findConsistentLogs in the editor below.
findConsistentLogs has the following parameters: int userEvent[n]: the userlds present in the event
logs
Returns
int. the maximum length if consistent logs
Constraints
1<=n<=3x105
1<=userEventli <=109

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!