Using one Set | Java
IntuitionScan the array and keep adding elements. For prefix it should be size of the set. We need to reset the set before suffix calculation. For suffix it sho
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Scan the array and keep adding elements. For prefix it should be size of the set. We need to reset the set before suffix calculation. For suffix it should be prefix - current size of set before adding the current element. 
# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```java []
class Solution {
    public int[] distinctDifferenceArray(int[] nums) {
        int n = nums.length;
        int ans[] = new int[n];
        Set<Integer>set = new HashSet<>();
        for(int i = 0; i<n; i++){
            set.add(nums[i]);
            ans[i] = set.size();
        }
        set.clear();
        for(int i = n-1; i>=0; i--){
            ans[i] = ans[i] - set.size();
            set.add(nums[i]);
        }
        return ans;
    }
}
```
['Java']