Java solution || 2 Solution || 0(N) || HashSet
Intuition\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 
# Intuition\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:0(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:0(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] distinctDifferenceArray(int[] nums) {\n        Set<Integer> left = new HashSet<>();\n        Set<Integer> right = new HashSet<>();\n        int len = nums.length;\n        int rightEle[] = new int[len];\n        int[] ans = new int[len];\n\n        rightEle[len-1] = 0;\n        for(int i=len-2; i>=0; i--){\n            right.add(nums[i+1]);\n            rightEle[i] = right.size();\n        }\n        for(int i=0; i<len; i++){\n            left.add(nums[i]);\n            ans[i] = left.size() - rightEle[i];\n        }\n       return ans;\n    }\n}\n\n// \n\n\n    //     int ans[] = new int[nums.length];\n    //     Set<Integer> set = new HashSet<>();\n    //     int count = 0;\n    //     for(int i=0; i<nums.length; i++){\n    //         set.add(nums[i]);\n    //         count = rightNums(nums,i);\n    //         ans[i] = set.size() - count;\n    //     }\n    //     return ans;\n    // }\n    //     public int rightNums(int[] nums, int j){\n    //     Set<Integer> right = new HashSet<>();\n    //     right.clear();\n    //     for(int i=j+1; i<nums.length; i++){\n    //         right.add(nums[i]);\n    //     }\n    //     return right.size();\n```
['Java']