Question: You are given an implementation of a function: class Solution { public int solution ( int M , int [ ] A ) ; that,

You are given an implementation of a function:
class Solution { public int solution(int M, int[] A);
that, given an integer M and an array A consisting of N non-negative integers,
which are not greater than M, returns the value (or one of the values) that occurs most often in this array.
For example, given M =3 and array A such that:
A[0]=1
A[1]=2
A[2]=3
A[3]=3
A[4]=1
A[5]=3
A[6]=1
the function may return 1 or 3.
The attached code is still incorrect for some inputs.
Despite the errors), the code may produce a correct answer for the example test cases.
The goal of the exercise is to find and fix the bugs) in the implementation. You can modify at most four lines.
Assume that:
N is an integer within the range [1.200,000];
M is an integer within the range [1.10,000];
each element of array A is an integer within the range [0..M].
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment. Write the answer Java

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 Programming Questions!