We can just use Unordered_set
\nvector<int> distinctDifferenceArray(vector<int>& nums) \n    {\n        unordered_set<int>st ;\n        int n = nums.size() ;\n        vector<int>pre(n+1 , 0)
```\nvector<int> distinctDifferenceArray(vector<int>& nums) \n    {\n        unordered_set<int>st ;\n        int n = nums.size() ;\n        vector<int>pre(n+1 , 0) , diff(n);\n        for(int i = 0 ; i < n ; i++)\n        {\n            int sz1 = st.size() ;\n            st.insert(nums[i]) ;\n            int sz2 = st.size() ;\n            if(sz1 != sz2)\n            {\n                pre[i+1] = pre[i]+1;\n            }\n            else\n            {\n                pre[i+1] = pre[i];\n            }\n        }\n        \n        unordered_set<int>st2 ;\n        vector<int> suf(n+1 , 0) ;\n        for(int i = n-1 ; i >= 0 ; i--)\n        {\n            int sz1 = st2.size() ;\n            st2.insert(nums[i]) ;\n            int sz2 = st2.size() ;\n            if(sz1 != sz2)\n            {\n                suf[i] = suf[i+1]+1;\n            }\n            else\n            {\n                suf[i] = suf[i+1];\n            }\n        }\n        \n        for(auto it : pre)\n        {\n            cout << it << " " ;\n        }\n        cout << endl;\n        for(auto it : suf)\n        {\n            cout << it << " " ;\n        }\n        int tt = st.size() ;\n        \n        for(int i = 1 ; i <= n ; i++)\n        {\n            diff[i-1] = pre[i] - suf[i] ;\n        }\n        \n        return diff ;\n        \n        \n    }\n```\n\nwe can just make two vectors for prefix and suffix by checking if size of a set is changing or not .\nOn subtracting prefix - suffix diffrence array will be created . \n
['C', 'Ordered Set']