Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function class Solution { public int solution ( int [ ] A ) ; } that, given an array A consisting of N

Write a function
class Solution { public int solution(int[] A); }
that, given an array A consisting of N integers, returns the biggest value X, which occurs in A exactly X times. If there is no such value, the function should return 0.
Examples:
1. Given A =[3,8,2,3,3,2], the function should return 3. The value 2 occurs exactly two times and the value 3 occurs exactly three times, so they both meet the task conditions. The value 8 occurs just once, thus it does not meet the task conditions. The maximum of 2 and 3 is 3.
2. Given A =[7,1,2,8,2], the function should return 2. The value 1 occurs exactly one time; the value 2 occurs exactly two times.
3. Given A =[3,1,4,1,5], the function should return 0. There is no value which meets the task conditions.
4. Given A =[5,5,5,5,5], the function should return 5.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000];
each element of array A is an integer within the range [1..1,000,000,000).
in c language

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

Students also viewed these Databases questions

Question

a cognitive reaction to the anticipation of future misfortune.

Answered: 1 week ago

Question

Understanding Groups

Answered: 1 week ago