Linear time complexity simple and easy approach with explanation...
Intuition\nUsing map as suffix and set as prefix.\n\n# Approach\nUsing the map as suffix and the set as prefix\nwhile we are traversing we put the current eleme
# Intuition\nUsing map as suffix and set as prefix.\n\n# Approach\nUsing the map as suffix and the set as prefix\nwhile we are traversing we put the current element in the prefix and then we see if there are more than one instance of that element exists then we will leave it in the prefix as well as suffix (or in the map and the set) if there was only one copy of that element was in the array then we remove it from the map (or the suffix ) and add into the prefix (set) and push the difference of their size in the ans vector.\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> distinctDifferenceArray(vector<int>& nums) {\n        unordered_map<int,int>mp; // first we stored all the elements in the map \n\n        for(auto it:nums){\n             mp[it]++;\n        }\n        set<int>st; // we used a set to store the prefix values\n        vector<int>ans;\n        for(auto it:nums){\n           st.insert(it); // we inserted it into the set\n           mp[it]--; // decremented the count of that element from the map used as suffix\n           if(mp[it]==0) mp.erase(it); // if there was only one element then we delete it from suffix and the return the size of diff of prefix-suffix that is set-map and if there was more than one value of that element was present then it will exist in both pre and suffix \n           ans.push_back(st.size()-mp.size());\n        }\n        return ans;\n    }\n};\n```
['Ordered Set', 'C++']