write a function
class Solution { public int solution(int N); }
that given an array A consisting of N integer, returns the biggest value X, which occurs exactly X times. if there is no such value, the function should return 0
Answers
Answered by
0
Answer:
Input: arr = {1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6}, k = 2
Output: 5
The elements that exactly occur 2 times are 1, 3 and 5
And, the largest element among them is 5.
Input: arr = {1, 2, 3, 4, 5, 6}, k = 2
Output: No such element
There isn't any element in the array
that occurs exactly 2 times.
Recommended: Please try your approach on {IDE} first, before moving on to the solution.
A simple approach:
Sort the array.
Start traversing the array from the end (as we’re interested in the largest element that satisfies the condition) and count the frequencies of each element by comparing the element.
HOPE THIS HELPS!!
PLEASE MARK ME AS BRAINLIEST!!?!
Answered by
0
Answer:
solution
please send answer
Similar questions