C++ | Math | Easy Solution
Please UpVote if it helps you\nApproach - don\'t think that robots are colliding each other, just add the d or subtract on ith robot\'s position if ith string i
# Please UpVote if it helps you\nApproach - don\'t think that robots are colliding each other, just add the `d` or subtract on `ith` robot\'s position if `ith` string is `R` and `L` respectively.\n\n# Code\n```\nclass Solution {\npublic:\n    int sumDistance(vector<int>& nums, string s, int d) {\n        int n = nums.size();\n        for(int i=0;i<n;++i){\n            if(s[i]==\'L\'){\n                nums[i] -= d;\n            }\n            else nums[i] += d;\n        }\n        sort(nums.begin(),nums.end());\n        long long sum = accumulate(nums.begin(),nums.end(),0LL);\n        long long ans = 0;\n        int mod = 1e9+7;\n        // take the sum of each pair\n        for(int i=0;i<n;++i){\n            sum -= nums[i];\n            ans +=abs( (long long)(n-i-1)*(nums[i]) - sum);\n            ans %= mod;\n        }\n        return ans;\n    }\n};\n```
['Math', 'Greedy', 'Brainteaser', 'Sorting', 'C++']