MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / countOccurence

Method countOccurence

CountMoreThanN-K.java:5–21  ·  view source on GitHub ↗
(int[] arr, int n, int k)

Source from the content-addressed store, hash-verified

3{
4 //Function to find all elements in array that appear more than n/k times.
5 public int countOccurence(int[] arr, int n, int k)
6 {
7 // your code here,return the answer
8 int barrier = n/k;
9 HashMap<Integer,Integer> map = new HashMap<>();
10 int counter=0;
11 for(int i=0;i<n;i++)
12 {
13 map.put(arr[i],map.getOrDefault(arr[i],0)+1);
14 }
15
16 for(Map.Entry<Integer,Integer> entry : map.entrySet())
17 {
18 if(entry.getValue()>barrier) counter++;
19 }
20 return counter;
21 }
22}
23// Brute Force Solution
24class Solution

Callers

nothing calls this directly

Calls 2

notInVisitedMethod · 0.95
getValueMethod · 0.80

Tested by

no test coverage detected