C++ solution ||100% beat using set
\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> distinctDifferenceArray(vector<int>& nums) {\n        int n=nums.size();\n        set<int>left;\n      
\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> distinctDifferenceArray(vector<int>& nums) {\n        int n=nums.size();\n        set<int>left;\n        vector<int>prefix(n);\n        for(int i=0;i<n;i++){\n            left.insert(nums[i]);\n            prefix[i]=left.size();\n        }\n        set<int>right;\n        vector<int>sufix(n);\n        for(int i=n-1;i>=0;i--){\n            sufix[i]=right.size();\n            right.insert(nums[i]);\n        }\n        vector<int>ans(n);\n        for(int i=0;i<n;i++){\n            ans[i]=prefix[i]-sufix[i];\n        }\n        return ans;\n        \n    }\n};\n```
['C++']