Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
640 views
Question 2
The developers working on a socal media network app want to analyze user behavor There are n eventlogs where user vent 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
Given n = 10, and userEvent = [1, 2, 1, 3, 4, 2, 4, 3, 3, 4]

* 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. on identia

Hence, the maximum length of consistent logs is 8.
Function Description
Complete the function findConsistentLogs in the editor below.
Rank Conic
findConsistentLogs has the following parameters: int userEvent[n]: the userlds present in the event logs
a
Returns

int. the maximum length of consistent logs
Constraints

* 1≤n≤ 3x105
* 1 ≤ userEvent] ≤ 10°
* Input Format For Custom Testing
The first line contains an integer n, the number of elements in user Event.51
Each line i of the n subsequent lines (where 0 &le; i < n) contains an integer, userEventli].
* Sample Case 0
Sample Input For Custom Testing
STDIN
Function
userEvent[] size n = 3
userEvent = [9, 9, 9]
Sample Output: 3
Explanation
The consistent logs are [9, 9, 9] because both the frequency of the least frequent user in the entire array and the frequency of the most frequent user in the subarray is 3.

7 Sample Case 1
Sample Input For Custom Testing
STDIN
Function
&rarr;
userEvent [] sizen = 5
userEvent = [9, 8, 5, 9, 2]
Sample output: 4
in Online Assessments by Expert (135,250 points) | 640 views

Please log in or register to answer this question.