Simple java code 3 ms beats 98.64 % && 45 mb beats 80.78 %
Complexity\n- \n# Code\n\nclass Solution {\n    public int[] distinctDifferenceArray(int[] nums) {\n        int n = nums.length;\n        int arr[] = new int[n]
# Complexity\n- ![image.png](https://assets.leetcode.com/users/images/8e61ce58-7968-4f61-be1f-cf10d248af4b_1707457812.1796923.png)\n# Code\n```\nclass Solution {\n    public int[] distinctDifferenceArray(int[] nums) {\n        int n = nums.length;\n        int arr[] = new int[n];\n        boolean[] freq = new boolean[51];\n        int count=0;\n        for(int i=0;i<n;i++){\n           if(!freq[nums[i]]){\n               freq[nums[i]] = true;\n                count++;\n           }\n           arr[i] = count;\n        }\n        count = 0;\n        freq = new boolean[51];\n        for(int i=n-1;i>=0;i--){\n            arr[i] -= count;\n            if(!freq[nums[i]]){\n               freq[nums[i]] = true;\n                count++;\n           }\n        }\n        return arr;\n    }\n}\n```
['Array', 'Hash Table', 'Java']