beats 100% || simple solution c++
\n\n# Approach\n Describe your approach to solving the problem. \nhere we use the technique of the hashmap \n-whether the elements are unique or not \n-by putti
![image.png](https://assets.leetcode.com/users/images/05ae6c6d-aa6e-40cb-b02e-e45724468ee0_1683433085.243885.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nhere we use the technique of the hashmap \n-whether the elements are unique or not \n-by putting them into hashmap \nand counting the distinct elements\n# Complexity\n- Time complexity:$O(n^2)$\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    int check(vector<int>& arr,int pos)\n    {\n        int hash1[51]={0};\n        int hash2[51]={0};\n        int first=pos;\n        int leftdistinct=0,rightdistinct=0;\n        int last=pos+1;\n        while(first>=0)\n        {\n            if(hash1[arr[first]]==0)\n            {hash1[arr[first]]=arr[first];\n                leftdistinct++;\n            }\n            first--;\n        }\n        while(last<arr.size())\n        {\n            if(hash2[arr[last]]==0)\n            {hash2[arr[last]]=arr[last];\n                rightdistinct++;\n            }\n            last++;\n        }\n        return leftdistinct-rightdistinct;\n    }\n    vector<int> distinctDifferenceArray(vector<int>& nums) \n    {\n        vector<int>ans;\n        for(int i=0;i<nums.size();i++)\n        {\n            ans.push_back(check(nums,i));\n        }\n        return ans;\n    }\n};\n```\n\n![e5cc6438-63d7-47fb-84d1-e4e36cf43c6e_1683003574.1370602.png](https://assets.leetcode.com/users/images/ec82e2cc-b1ea-4e5b-889c-8e6d692fab9d_1683433036.901454.png)\n
['Hash Table', 'C', 'Suffix Array', 'C++']