🔥C++ ✅✅ Best Solution ( 🔥 set + prefix & suffix🔥 ) Easy to Understand💯💯 ⬆⬆⬆
\n\n# Complexity\n- Time complexity: O(n logn)\n Add your time complexity here, e.g. O(n) \n\n\n- Space complexity: O(4n)\n Add your space complexity here, e.g.
>\n\n# Complexity\n- Time complexity: $$O(n logn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity: $$O(4n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> distinctDifferenceArray(vector<int>& nums) {\n        set<int> suffSet, prefSet;\n        vector<int> suff(nums.size()), pref(nums.size()), ans(nums.size());\n        \n        for(int i=0; i<nums.size(); i++)   \n            suffSet.insert(nums[i]), suff[i] = suffSet.size();\n        \n        for(int i=nums.size() - 1; i>=0; i--)   \n            pref[i] = prefSet.size(), prefSet.insert(nums[i]);\n        \n        for(int i=0; i<nums.size(); i++)    ans[i] = suff[i] - pref[i];\n        return ans;\n    }\n};\n```
['Array', 'Suffix Array', 'Prefix Sum', 'Ordered Set', 'C++']