for(int i = 0; i<n; i++){
if(hs.containsKey(arr2[i])){
ar.add(arr2[i]);
int val = hs.get(arr2[i]) - 1;
if(val != 0){
hs.put(arr2[i], val);
}
if(val == 0)
hs.remove(arr2[i]);
}
}
Collections.sort(ar);
System.out.print(ar);
}
}
for(int i = 0; i<n; i++){
if(hs.containsKey(arr2[i])){
ar.add(arr2[i]);
int val = hs.get(arr2[i]) - 1;
if(val != 0){
hs.put(arr2[i], val);
}
if(val == 0)
hs.remove(arr2[i]);
}
}
Collections.sort(ar);
System.out.print(ar);
}
}
No the output that is coming is this [1, 2, 2, 3] and the required one is [1, 1, 2, 2, 3]