Suffix + Prefix + Traverse (R-75%+, M-40%+)
Complexity
Time complexity: O(n)
n - length of the input array nums

Space complexity: O(n)
Code
# Complexity
- Time complexity: **O(n)**
**n** - length of the input array `nums`
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: **O(n)**
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def distinctDifferenceArray(self, nums: List[int]) -> List[int]:
        distincts: set[int] = set()
        # prefix inclusive
        prefixes: list[int] = [0 for _ in range(len(nums))]
        for index in range(len(nums)):
            distincts.add(nums[index])
            prefixes[index] = len(distincts)
        # suffix !inclusive
        # We need to start from the second_last => include last by default.
        distincts = {nums[-1]}
        suffixes: list[int] = [0 for _ in range(len(nums))]
        for index in range(len(nums) - 2, -1, -1):
            suffixes[index] = len(distincts)
            distincts.add(nums[index])
        out: list[int] = [
            prefixes[index] - suffixes[index] for index in range(len(nums))
        ]
        return out
```
['Array', 'Hash Table', 'Python3']