Get Mystery Box with random crypto!

INTEGER +========+ Given an integer arrary arr. Count how many | Programming Challenges - How to be a breathtaking Programmer

INTEGER
+========+
Given an integer arrary arr. Count how many elements X there are, such that X+1 is also in arr. If there're duplicates in arr, count them separately.

Example 1:
Input: arr = [1,2,3]
Output: 2

EXPLANATION :
There are 2 such elements: 1 and 2 because 2 and 3 are also in the arrary.

Example 2:
Input: arr = [1,1,3,3,5,5,7,7]
Output: 0

EXPLANATION :
There's no such number because 2, 4, 6 or 8 is not present in the arrary.

Example 3:
Input: arr = [1,3,2,3,5,0]
Output: 3

EXPLANATION:
There are 3 such numbers 0, 1 and 2 because 1, 2 and 3 are in the arrary.

Example 4:
Input: arr = [1,1,2,2]
Output: 2

EXPLANATION:
There are 2 such numbers 1 and 1 because 2 is in the arrary and duplicates are counted separately.

Example 5:
Input: arr = [1,1,2]
Output: 2

EXPLANATION:
There are 2 such numbers: 1 and 1 because 2 is in the arrary and duplicates are counted separately.
+========+
Thanks to star prince for this suggestion!