Simple prefix sum : movement-of-robot
Intuition\n Describe your first thoughts on how to solve this problem. \nThere is no difference if we do not perform collision condition as distance between rob
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere is no difference if we do not perform collision condition as distance between robots remain same.\nincrement robot position by 1 if robot direction is RIGHT;\ndecrement robot position by 1 if robot direction is LEFT;\n\n![image.png](https://assets.leetcode.com/users/images/369088ae-90c8-4995-8c38-e27096815c48_1686572141.6413007.png)\n\n![image.png](https://assets.leetcode.com/users/images/d30b01b5-2305-457e-9583-ba6bbd907baf_1686572006.2560692.png)\n\n\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nsum of pair of difference.\n![image.png](https://assets.leetcode.com/users/images/cb034448-5d77-4574-8319-463123b3a5f3_1686571450.1095605.png)\nprefixsum is\nprefixsum+=nums[i];\n \n\n\n# Complexity\n- Time complexity:O(nlogn): in sorting\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```\nclass Solution {\npublic:\n    int sumDistance(vector<int>& nums, string s, int d) {\n        int n=nums.size();\n        int M=1e9+7;\n        for(int i=0;i<n;i++){\n            if(s[i]==\'R\')\n                nums[i]=(nums[i]+d);\n            else\n                nums[i]=(nums[i]-d);\n        }\n        int sum=0,prefixsum=0;\n        sort(nums.begin(),nums.end());\n        for(int i=0;i<n;i++){\n                sum=(sum%M+(i*1ll*nums[i]-prefixsum)%M )%M;\n                prefixsum=(prefixsum%M+ nums[i]%M)%M;;\n        }\n        return sum;       \n    }\n};\n```
['Prefix Sum', 'C++']