Prefix sum algorithm without unnecessary actions and iterations
\nvar distinctDifferenceArray = function(nums) {\n    const set = new Set()\n    const res = []\n    \n    for (let num of nums) {\n        set.add(num)\n      
```\nvar distinctDifferenceArray = function(nums) {\n    const set = new Set()\n    const res = []\n    \n    for (let num of nums) {\n        set.add(num)\n        res.push(set.size)\n    }\n    \n    set.clear()\n    \n    for (let i = nums.length - 1; i >= 0; i--) {\n        res[i] = res[i] - set.size\n        set.add(nums[i])\n    }\n    \n    return res\n};\n```
['JavaScript']