Easy solution in java (Just maintain prefix and suffix array)
IntuitionJust maintain prefix and suffix and calculate difference accordinglyApproachComplexity
Time complexity:
O(N)
Space complexity:
O(N)Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Just maintain prefix and suffix and calculate difference accordingly
# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(N)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(N)
# Code
```java []
class Solution {
    public int[] distinctDifferenceArray(int[] nums) {
       int prefixDistinct[] = new int [nums.length];
       int suffixDistinct[] = new int [nums.length];
       int difference[] = new int[nums.length];
       Set<Integer> st = new HashSet<>();
       for(int i=0;i<nums.length;i++) {
         st.add(nums[i]);
         prefixDistinct[i] = st.size();
       } 

        st.clear();
        for(int i=nums.length-1;i>=0;i--) {
         st.add(nums[i]);
         suffixDistinct[i] = st.size();
       }

       for(int i=0;i<nums.length-1;i++) {
         difference[i] = prefixDistinct[i]-suffixDistinct[i+1];
       }
       difference[nums.length-1] =  prefixDistinct[nums.length-1];
       return difference;
    }
}
```
['Prefix Sum', 'Java']