-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmovezero.java
More file actions
35 lines (34 loc) · 983 Bytes
/
movezero.java
File metadata and controls
35 lines (34 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.HashMap;
import java.util.Map;
public class movezero{
public static void main(String args[]){
Map<Integer,Integer>frq=new HashMap<>();
int arr[]={1,3,2,1,4,1};
int n=arr.length;
// for(int i=0;i<n-1;i++){
// for(int j=0;j<n-1-i;j++){
// if(arr[j]==0&&arr[j+1]!=0){
// int temp=arr[j];
// arr[j]=arr[j+1];
// arr[j+1]=temp;
// }
// }
// }
for(int i:arr){
if(!frq.containsKey(i)){
frq.put(i,1);
}else{
frq.put(i,frq.get(i)+1);
}
}
int maxFreq=0,ansKey=-1;
for(var e:frq.entrySet()){
if(e.getValue()>maxFreq){
maxFreq=e.getValue();
ansKey=e.getKey();
}
System.out.println(maxFreq);
System.out.println(ansKey);
}
}
}