Optimized simple solution - beats 92.08%🔥
Complexity
Time complexity:

Space complexity:
Code
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```java []
class Solution {
    public int[] distinctDifferenceArray(int[] nums) {
        HashSet<Integer> h = new HashSet<>();
        int[] sum = new int[nums.length];
        int[] sumr = new int[nums.length + 1];

        int currSum = 0;
        int j = 0;
        for (int i : nums) {
            if (!h.contains(i)) {
                h.add(i);
                currSum++;
            }
            sum[j++] = currSum;
        }
        h.clear();
        currSum = 0;
        for (int i = nums.length - 1; i > -1; i--) {
            if (!h.contains(nums[i])) {
                h.add(nums[i]);
                currSum++;
            }
            sumr[i] = currSum;
        }

        for (int i = 0; i < nums.length; i++) {
            nums[i] = sum[i] - sumr[i + 1];
        }
        return nums;
    }
}
```
['Java']