Easy to understand solution in Java.
Complexity

Time complexity:
O(n^2)


Space complexity:
O(n)

Code
# Complexity
- Time complexity:
O(n^2)

- Space complexity:
O(n)

# Code
```java []
class Solution {
    public int[] distinctDifferenceArray(int[] nums) {
        int n = nums.length;
        int[] result = new int[n];
        Set<Integer> prefixSet = new HashSet<>();

        for (int i = 0; i < n; i++) {
            prefixSet.add(nums[i]);

            Set<Integer> suffixSet = new HashSet<>();
            for (int j = i + 1; j < n; j++) {
                suffixSet.add(nums[j]);
            }
            result[i] = prefixSet.size() - suffixSet.size();
        }
        return result;
    }
}
```
['Array', 'Java']