In: Computer Science
Problem 1:
Given an array A[0 ... n-1], where each element of the array represents a vote in the election. Assume that each vote is given as integers representing the ID of the chosen candidate. Write the code determining who wins the election.
Problem 2:
How do we find the number which appeared maximum number of times in an array?
( Use Java and an original code )
Problem 1 : To find the maximum votes for a candidate we can use hashMap and find the occurance of each item in the array.
Output :
Problem 2 : This is same as above problem as the technique used to solve above problem is : maximum frequency element in an array. but I have given screenshot of that code too.
Output : element with max frequency : 1