Java easy solution using HashMap
Intuition \nThe brute fore method i have used but it can be optimised using hashset in a single loop.\n Describe your first thoughts on how to solve this proble
# Intuition \nThe brute fore method i have used but it can be optimised using hashset in a single loop.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] distinctDifferenceArray(int[] nums) {\n        int n = nums.length;\n        HashMap<Integer,Integer> prefix = new HashMap<>();\n        HashMap<Integer,Integer> suffix = new HashMap<>();\n        int[] ans = new int[nums.length];\n        int[] prearr = new int[nums.length];\n        int[] suffarr = new int[nums.length];\n\n        int k =0;\n        int x = 0;\n        for(int i=0; i<nums.length; i++){\n            for(int j =0; j<=i; j++){\n                if(!prefix.containsKey(nums[j])){\n                    prefix.put(nums[j],1);\n                }\n            }\n            int pref_val = prefix.size();\n            k++;\n\n            // System.out.println( prefix.size() + " prefix");\n            \n            int count = 0;\n            for(int j = i+1; j<n; j++){\n                \n                if(!suffix.containsKey(nums[j])){\n                    suffix.put(nums[j],1);\n                }\n                \n            }\n            int suff_val = suffix.size();\n            suffix.clear();\n\n            ans[i] = pref_val - suff_val;\n            \n            System.out.println(suff_val);\n        }\n        \n        \n       \n        \n        return ans;\n    }\n}\n```
['Array', 'Hash Table', 'Two Pointers', 'Iterator', 'Java']