Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an array of integers, arr, of size n , that represent the frequency of each element, for each element, do exactly one of these

Given an array of integers, arr, of size n, that represent the frequency of each element, for each element, do exactly one of these operations:
1. Leave the frequency unchanged.
2. Increase the frequency of the element by x.
3. Decrease the frequency of the element by y.
4. Multiply the frequency of the element by z.
Find the maximum number of elements with the same frequency that can be obtained.
Example
X=1
y=1
z=3
n=4
arr =[1,2,4,10]
frequency.
After these operations, the array is [3,3,3,10]. Return 3, the number of elements that are equal in
Function Description
Complete the function findMaxFrequency in the editor below.
findMaxFrequency has the following parameters: int x: the value used in the second operation int y: the value used in the third operation
To obtain the maximum number of elements with the same frequency, do these operations.
Values
arr[0]=1
Operation Applied
New Value
arr[1]=2
4(Multiply by z)
1*3=3
arr[2]=4
2(Increase by x)
2+1=3
arr[3]=10
3(Decrease by Y)
1(Keep unchanged)
4-1=3
10
int z: the value used in the fourth operation int arr[i]: the frequency of each element to equalize
Returns
int: the maximum number of equal frequencies that can be obtained
Constraints
1<=n<=10^5
1<= arr[i]<=10^5
1<=x, y <=10^4
1<=z<=10^4
Input Format for Custom Testing
The first line contains an integer x.
The next line contains an integer y.
The next line contains an integer z.
The next line contains an integer n, the size of arr[i] Each of the next n lines contains an integer, arr[i].

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Cost Reduction Systems Target Costing And Kaizen Costing

Authors: Yasuhiro Monden

1st Edition

1563270684, 978-1563270680

Students also viewed these Databases questions