class Solution: def countElements(self, arr): hm = dict() for n in arr: if n in hm: hm[n] += 1 else: hm[n] = 1 count = 0 for key, value in hm.items(): if key + 1 in hm: count += hm[key] return count s = Solution() print("Expected: 2") print("Got:", s.countElements([1, 2, 3]))