LeetCode solutions

3163. Subarrays Distinct Element Sum of Squares I

My accepted Python solution to LeetCode problem 3163, Subarrays Distinct Element Sum of Squares I, running in 23ms.

  • Difficulty: Easy
  • Python
  • Runtime 23ms
  • Memory 17MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 23ms, memory 17MB, accepted 2026-01-01.

python
class Solution:
    def sumCounts(self, nums: List[int]) -> int:
        n = len(nums)
        result = 0
        
        for i in range(n):
            seen = set()
            for j in range(i, n):
                seen.add(nums[j])
                result += len(seen) ** 2
        
        return result

Source