[JavaScript] 2670. Find the Distinct Difference Array
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n\n```\nconst distinctDifferenceArray = function (a) {\n  const n = a.length\n  const pre = new Array(n) // prefix counts\n  const suf = new Array(n) // suffix counts\n  let set\n\n  set = new Set()\n  for (let i = 0; i < n; i++) {\n    set.add(a[i])\n    pre[i] = set.size\n  }\n\n  set = new Set()\n  for (let i = n - 1; i >= 0; i--) {\n    suf[i] = set.size\n    set.add(a[i])\n  }\n\n  const an = new Array(n)\n  for (let i = 0; i < n; i++) {\n    an[i] = pre[i] - suf[i]\n  }\n  return an\n}\n```\n
['JavaScript']