> For the complete documentation index, see [llms.txt](https://adit0503.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adit0503.gitbook.io/leetcode/x.-counting-elements.md).

# X. Counting Elements

Easy

Given an integer array `arr`, count element `x` such that `x + 1` is also in `arr`. \
If there're duplicates in `arr`, count them separately.

## :innocent: [Solution](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3289/)

{% tabs %}
{% tab title="O(n2)" %}

```python
class Solution:
    def countElements(self, arr: List[int]) -> int:
        
        count = 0
        
        for a in arr:
            if a+1 in arr:
                count += 1
                
        return count
```

{% endtab %}
{% endtabs %}
