Short C++ code (single iteration)
Intuition\n Describe your first thoughts on how to solve this problem. \nUse unordered_set to know count of unique element in a running iteration.\n\n# Approach
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse unordered_set to know count of unique element in a running iteration.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nus1 will give unqiue element count for the prefix part and us2 will give unique element count for suffix part. Since, in answer we want prefix-suffix, prefix part\'s count is added and suffix\'s count is subtracted. The reason of subtracting before inserting to us2 is because suffix part starts from i+1.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> distinctDifferenceArray(vector<int>& nums) {\n        int n =  nums.size();\n        vector<int> ans(n,0);\n        unordered_set<int> us1,us2;\n        for(int i = 0; i < n; i++){\n            us1.insert(nums[i]);\n            ans[n-i-1] -= us2.size();\n            us2.insert(nums[n-i-1]);\n            ans[i] += us1.size();\n        }\n        return ans;\n    }\n};\n```
['C++']