C++ Solution Using Unordered Maps||100% efficient
Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n# Code
# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\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        unordered_map<int,int> before,after;\n        vector<int> ans;\n        //first put every element in the after map..\n        for(int i=0;i<nums.size();i++){\n            after[nums[i]]++;\n        }\n        //now remove ith nums from the after map and add it in the before map then calculte the diff and put it in the vector named ans;\n        for(int i=0;i<nums.size();i++){\n            after[nums[i]]--;\n            before[nums[i]]++;\n            //if frequency of nums[i] in after map is 0 then remove it so we don\'t count it in the calculation..\n            if(after[nums[i]]==0)\n               after.erase(nums[i]);\n             ans.push_back(before.size()-after.size());  \n        }\n        return ans;\n    }\n};\n```
['C++']