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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 23ms, memory 17MB, accepted 2026-01-01.
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