LeetCode solutions

2777. Find the Distinct Difference Array

My accepted Python solution to LeetCode problem 2777, Find the Distinct Difference Array, running in 23ms.

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 23ms, memory 12.5MB, accepted 2025-12-24.

python
class Solution(object):
    def distinctDifferenceArray(self, nums):
        n = len(nums)
        result = []
        for i in range(n):
            prefix = len(set(nums[:i+1]))
            suffix = len(set(nums[i+1:]))
            result.append(prefix - suffix)
        return result

Source