LeetCode solutions

2277. Count Equal and Divisible Pairs in an Array

My accepted Python solution to LeetCode problem 2277, Count Equal and Divisible Pairs in an Array, running in 35ms.

  • Difficulty: Easy
  • Python
  • Runtime 35ms
  • Memory 12.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 35ms, memory 12.3MB, accepted 2025-12-24.

python
class Solution(object):
    def countPairs(self, nums, k):
        count = 0
        n = len(nums)
        for i in range(n):
            for j in range(i + 1, n):
                if nums[i] == nums[j] and (i * j) % k == 0:
                    count += 1
        return count

Source