LeetCode 1512, Easy. Topics: Array, Hash Table, Math, Counting. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:
Problem
Given an array of integers nums, return the number of good pairs.
A pair (i, j) is called good if nums[i] == nums[j] and i < j.
Examples
Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.
Explanation: Each pair in the array are good.
Constraints
- 1 <= nums.length <= 100
- 1 <= nums[i] <= 100
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026