LeetCode solutions

2122. Count Special Quadruplets

My accepted Python solution to LeetCode problem 2122, Count Special Quadruplets, running in 543ms.

  • Difficulty: Easy
  • Python
  • Runtime 543ms
  • Memory 17.1MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 543ms, memory 17.1MB, accepted 2025-12-29.

python
class Solution:
    def countQuadruplets(self, nums: List[int]) -> int:
        n = len(nums)
        count = 0
        for a in range(n):
            for b in range(a + 1, n):
                for c in range(b + 1, n):
                    for d in range(c + 1, n):
                        if nums[a] + nums[b] + nums[c] == nums[d]:
                            count += 1
        return count

Source