This code is giving me wrong output

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);
}

}

LINK OF FULL CODE: https://ide.codingblocks.com/s/616246

Hi @ayush_r18
Your code is running absolutely fine

No the output that is coming is this [1, 2, 2, 3] and the required one is [1, 1, 2, 2, 3]