LeetCode 1426, Easy. Topics: Array, Hash Table. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 26 parametrized pytest cases, and a playground notebook:
Problem
Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them separately.
Examples
Constraints
- 1 <= arr.length <= 1000
- 0 <= arr[i] <= 1000
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026