(int[] arr, int n, int k)
| 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 |
| 24 | class Solution |
nothing calls this directly
no test coverage detected