| 1. |
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 |
|
Answer» Input: arr = {1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6}, K = 2Output: 5The elements that exactly occur 2 times are 1, 3 and 5And, the LARGEST element AMONG them is 5.Input: arr = {1, 2, 3, 4, 5, 6}, k = 2Output: No such elementThere isn't any element in the arraythat 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!!?! |
|