C#, Hashset
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n\npublic class Solution \n{\n    public int[] DistinctDifferenceArray(int[] nums) \n 
# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\npublic class Solution \n{\n    public int[] DistinctDifferenceArray(int[] nums) \n    {\n        int n = nums.Length;\n        int[] result = new int[n];\n        HashSet<int> distinctElements = new HashSet<int>();\n\n        distinctElements.Add(nums[n-1]);\n        for (int i = n - 2; i >= 0; i--)\n        {\n            result[i] = -distinctElements.Count;\n            distinctElements.Add(nums[i]);\n        }\n\n        distinctElements.Clear();\n\n        for (int i = 0; i <= n - 1; i++)\n        {\n            distinctElements.Add(nums[i]);\n            result[i] += distinctElements.Count;\n        }\n\n        return result;\n    }\n}\n```
['C#']