Java simple approach | using Hashset for unique difference
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n.define array for stori
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n.define array for storing value after find difference \nint [] diff = new int[n];\n. find prefix \n.find suffix\n.find prefix.size()-suffix.size();\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N*N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n# Code\n```\nclass Solution {\n    public int[] distinctDifferenceArray(int[] nums) {\n                int n = nums.length;\n        int[] diff = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            Set<Integer> prefix = new HashSet<>();\n            for (int j = 0; j <= i; j++) {\n                prefix.add(nums[j]);\n            }\n\n            Set<Integer> suffix = new HashSet<>();\n            for (int j = i + 1; j < n; j++) {\n                suffix.add(nums[j]);\n            }\n\n            diff[i] = prefix.size() - suffix.size();\n        }\n\n        return diff;\n    }\n}\n```
['Java']