C++ O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\ncollision does not change the overall final positions of the robot;\nIn c
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\ncollision does not change the overall final positions of the robot;\nIn case 1 final positions are\nrobot1 -> -3\nrobot2 -> -1\nrobot3 -> 1\nabs(-3 - (-1)) + abs(1 - (-1)) + abs(1 - (-3)) = 8\nso if we simply add or subtract d after checking the \'R\' && \'L\' we get\nrobot1 -> 1\nrobot2 -> -3\nrobot3 -> -1\nwhich will also give the same final result  abs(-3 - 1) + abs(-1 - (-3)) + abs(-1 - 1) = 8\n\n# Complexity\n- Time complexity:\n<!-- O(N); -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define ll long long\nclass Solution {\npublic:\n    ll M = 1e9 + 7;\n    ll sumDistance(vector<int>& nums, string s, ll d) {\n        vector<ll> v;\n        for(auto it : nums)\n                v.push_back(it);\n        ll n = s.size();\n        for(int i = 0; i < n; i++)\n        {\n            if(s[i] == \'L\')\n                v[i] -= d;\n            else\n                v[i] += d;\n        }\n        \n        sort(v.begin(), v.end());\n        ll ans = 0;\n        for (ll i = 0; i < n; i++)\n        {\n            ans += (1LL * i * v[i]) - (1LL * (n - 1 - i) * v[i]);\n            ans = (ans + (n + 2) * M) % M;\n        }\n        \n        return ans % M;\n        \n    }\n};\n```
['C++']