✔ Best simple java solution
\n# 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
\n# 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 {\n    public int[] distinctDifferenceArray(int[] nums) {\n        int n = nums.length;\n        HashMap<Integer,Integer> map1 = new HashMap<>();\n        HashMap<Integer,Integer> map2 = new HashMap<>();\n        for(int i=0;i<n;i++)\n        {\n            map2.put(nums[i],map2.getOrDefault(nums[i],0)+1);\n        }\n        int[] diff = new int[n];\n        for(int i=0;i<n;i++)\n        {\n            map2.put(nums[i],map2.get(nums[i])-1);\n            if(map2.get(nums[i])==0) map2.remove(nums[i]);\n            map1.put(nums[i],map1.getOrDefault(nums[i],0)+1);\n            diff[i] = map1.size()-map2.size();\n        }\n        return diff;\n    }\n}\n```
['Java']