Using One HashSet
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# 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> distinctNumbers = new HashSet<>();
        int[] res = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            distinctNumbers.add(nums[i]);
            res[i] = distinctNumbers.size();
        }
        distinctNumbers = new HashSet<>();
        for (int i = nums.length - 1; i >= 0; i--) {
            res[i] = res[i] - distinctNumbers.size();
            distinctNumbers.add(nums[i]);
            
        }

        return res;
    }
}
```
['Array', 'Java']