BEST C++ || O(nlogn)|| Proper Intution || Easy to understand
Intution\nWhen collision happens- Directions wil be RL or LR and in that case direction will change as  LR or RL respectively. So, there is no net effect in ans
# Intution\nWhen collision happens- Directions wil be RL or LR and in that case direction will change as  LR or RL respectively. So, there is no net effect in answer even calculating without changing the direction.\n# Complexity\n- Time complexity:O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define md 1000000007\nclass Solution {\npublic:\n\nint sumDistance(vector<int>& nums, string s, int d) {\n    long long n=nums.size();\n    vector<long long>nums1(nums.begin(),nums.end());\n    for(long long i=0;i<n;i++){\n        if(s[i]==\'L\')nums1[i]-=d;\n        else nums1[i]+=d;\n\n    }\n    \n//An efficient solution for this problem needs a simple observation. Since array is sorted and elements are distinct when we take sum of absolute difference of pairs each element in the i\u2019th position is added \u2018i\u2019 times and subtracted \u2018n-1-i\u2019 times.\nsort(nums1.begin(),nums1.end());\nfor(long long i=0;i<n;i++)nums1[i]%=md;\nlong long answer=0;\nfor(long long i=0;i<n;i++){\n    long long temp1=(i*nums1[i])%md;\n    long long temp2=((n-1-i)*nums1[i])%md;\n    answer+=((temp1-temp2));\n    answer%=md;\n    if(answer<0)answer+=md;//Very Important step to do.\n}\nanswer%=md;\nreturn (int)answer;\n    }\n};\n```
['C++']