L2R + R2L
C++\ncpp\nvector<int> distinctDifferenceArray(vector<int>& nums) {\n    int cnt[51] = {}, dist = 0;\n    vector<int> res;\n    for (int n : nums)\n        res.p
**C++**\n```cpp\nvector<int> distinctDifferenceArray(vector<int>& nums) {\n    int cnt[51] = {}, dist = 0;\n    vector<int> res;\n    for (int n : nums)\n        res.push_back((res.empty() ? 0 : res.back()) + (cnt[n]++ == 0));\n    for (int i = nums.size() - 1; i >= 1; --i) {\n        dist += exchange(cnt[nums[i]], 0) > 0;\n        res[i - 1] -= dist;        \n    }\n    return res;\n}\n```
[]