Skip to content

Commit

Permalink
Create frequency array
Browse files Browse the repository at this point in the history
  • Loading branch information
scanurag authored Aug 31, 2023
1 parent eab972b commit 094ec80
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Arrays/frequency array
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Arrays;
import java.util.*;
public class FrequencyArray {
public static void main(String[] args) {
int[] a= {1,2,1,2,1,5,7,7,7};
findNum(a);
}
public static void findNum(int[] a) {
HashMap<Integer,Integer> mp=new HashMap<>();
for(int i=0;i<a.length;i++) {
mp.put(a[i],mp.get(a[i])==null ?1:mp.get(a[i])+1);
}
for(int i=0; i<a.length;i++) {
if(mp.get(a[i])!=-1) {
System.out.println(a[i]+" "+mp.get(a[i]));
mp.put(a[i],-1);
}
}
}
}

0 comments on commit 094ec80

Please sign in to comment.