class Solution { public int countElements(int[] arr) { int count=0; HashSet<Integer> hs = new HashSet<>(); for(int num : arr){ hs.add(num); } for(int num : arr){ if(hs.contains(num+1)){ count++; } } return count; } }