Set, Prefix and Suffix
\nFirst thought - The length of input is small. To find the number of distinct numbers, we can use Set. Therefore, we can iterate each number, put nums[:i + 1] 
\nFirst thought - The length of input is small. To find the number of distinct numbers, we can use Set. Therefore, we can iterate each number, put `nums[:i + 1]` and `nums[i + 1:]` to Set,  count the lengths and calculate the difference.\n\n```py\nclass Solution:\n    def distinctDifferenceArray(self, nums: List[int]) -> List[int]:\n        res = []\n        for i in range(len(nums)):\n            res.append(len(set(nums[:i + 1])) - len(set(nums[i + 1:])))\n        return res\n```\n\nHere\'s the one-liner of the above solution.\n\n```py\nclass Solution:\n    def distinctDifferenceArray(self, nums: List[int]) -> List[int]:\n        return [len(set(nums[:i + 1])) - len(set(nums[i + 1:])) for i in range(len(nums))]\n```\n\nHowever, in above solution, it is not optimize as we slice the list for each index. To improve it, we can use prefix and suffix. The logic is similar. For each index, we add `nums[i]` in set and record the length. \n\n```py\nclass Solution:\n    def distinctDifferenceArray(self, nums: List[int]) -> List[int]:\n        pre, suf = [], []\n        ps, ss = set(), set()\n        n = len(nums)\n        for i in range(n):\n            ps.add(nums[i])\n            pre.append(len(ps))\n        for i in range(n - 1, -1, -1):\n            suf.insert(0, len(ss))\n            ss.add(nums[i])\n        # pre: [1, 2, 3, 4, 5]\n        # suf: [4, 3, 2, 1, 0]\n        # ans: [-3, -1, 1, 3, 5]\n        return [pre[i] - suf[i] for i in range(n)]\n```
['Ordered Set', 'Python']