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 userEventi 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 and userEvent
The frequencies of and are
The frequencies of and are
The minimum frequency in the array is
The longest valid subarray has elements:
The frequencies of and are all
The frequency of the most common element in the subarray is the same as the minimum frequency in the entire array.
Hence, the maximum length of consistent logs is
Function Description
Complete the function findConsistentLogs in the editor below.
findConsistentLogs has the following parameters: int userEventn: the userlds present in the event
logs
Returns
int. the maximum length if consistent logs
Constraints
nx
userEventli
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
