Simplest Approach
Intuition
The problem requires calculating the difference between distinct element counts in prefix and suffix subarrays.
By maintaining a frequency map, we eff
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- The problem requires calculating the difference between distinct element counts in prefix and suffix subarrays. 
- By maintaining a frequency map, we efficiently track distinct elements at each index.

# Approach
<!-- Describe your approach to solving the problem. -->
- Compute the pre array where pre[i] stores the number of distinct elements from index 0 to i.
- Compute the suf array where suf[i] stores distinct elements from index i to n-1, then adjust pre[i] using suf[i+1] to get the final result.

# 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
```cpp []
class Solution {
public:
    vector<int> distinctDifferenceArray(vector<int>& nums) {
        int n = nums.size();
        vector<int> pre(n), suf(n);
        unordered_map<int, int> dist_map;
        
        // Calculate distinct counts for the 'pre' array
        for (int i = 0; i < n; i++) {
            dist_map[nums[i]]++;
            pre[i] = dist_map.size();
        }
        
        // Clear the map for 'suf' calculation
        dist_map.clear();
        
        // Calculate distinct counts for the 'suf' array (from end to start)
        for (int i = n - 1; i >= 0; i--) {
            dist_map[nums[i]]++;
            suf[i] = dist_map.size();
        }
        
        // Final adjustment of the 'pre' array
        for (int i = 0; i < n - 1; i++) {
            pre[i] -= suf[i + 1];
        }
        
        return pre;
    }
};

```
['C++']