Video Explanation (With Intuition)
Explanation\n\nClick here for the video\n\n# Code\n\ntypedef long long int ll;\nconst int MOD = 1e9+7;\n\nclass Solution {\npublic:\n    int sumDistance(vector<
# Explanation\n\n[Click here for the video](https://youtu.be/Xpr0hg1jBEI)\n\n# Code\n```\ntypedef long long int ll;\nconst int MOD = 1e9+7;\n\nclass Solution {\npublic:\n    int sumDistance(vector<int>& nums, string s, int d) {\n        int n = nums.size();\n        \n        vector<ll> final_pos(n);\n        for (int j = 0; j < n; j ++) \n            final_pos[j] = (ll)nums[j] + (s[j] == \'L\'? -d : d);\n        \n        sort (final_pos.begin(), final_pos.end());\n        \n        ll result = 0;\n        ll prefix = 0;\n        for (int j = 0; j < n; j ++) {\n            result = (result + (final_pos[j]*j - prefix + MOD)) % MOD;\n            prefix = (prefix + final_pos[j]) % MOD;\n        }\n        \n        return result;\n    }\n};\n```
['C++']