Java Using HashSet SC :- O(n)
Intuition\n Describe your first thoughts on how to solve this problem. \nArrays using HashSet as we had a special property in HashSet that it won\'t store any e
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nArrays using HashSet as we had a special property in HashSet that it won\'t store any element twice.\n\n# Approach\nCreate a 2 new arrays one to have prefix unique elements and another for suffiix and subract values as per repuirement \nHere - prefix[i] - suffix[i+1]\n<!-- Describe your approach to solving the problem. -->\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        HashSet<Integer> hs = new HashSet<Integer>();\n        int i, len = nums.length;\n        int[] prefix = new int[len];\n        int[] suffix = new int[len];\n        for(i=0;i<len;i++){\n            hs.add(nums[i]);\n            prefix[i] = hs.size();\n        }\n        hs.clear();\n        for(i=len-1;i>=0;i--){\n            hs.add(nums[i]);\n            suffix[i] = hs.size();\n        }\n        for(i=0;i<len-1;i++){\n            nums[i] = prefix[i] - suffix[i+1];\n        }\n        nums[len-1] =  prefix[len-1];\n        return nums;\n    }\n}\n```
['Array', 'Suffix Array', 'Java']