BEST IMPLEMENTATION | EASY | C++ CODE | ANS REVIEW PLS
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n all the robots are of same characterstics ....\n so , after colliding they have ju
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n all the robots are of same characterstics ....\n* so , after colliding they have just effect of directions ..  so we can think robots surpass each other instead of thinking they collided\n\n* after d seconds all the robots at there same area... means if robot at left most then after d second it remains at left , if in middle remains in middle\n\n* if at rightmost then remain at that\n* so sort that array and calculate the distance between each pair----> In O(n) times\n\nhow?  see ----->   ---a---------b-------------c---------------d--------------e-----\n            b-a          c-a             d-a             e-a\n                        c-b              d-b             E-B E-B                                      d-c              e-c      \n                                                          e-d                           \n    //                        (1xb-a)        (2xc-(a+b))    (3xd-(a+b+c))  (3xe-(a+b+c+d))\n    // addition of all this == ans\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int mod = 1e9 + 7; \n    int sumDistance(vector<int>& nums, string s, int d) {\n        int n = nums.size();\n        for(int i=0 ; i<n ;i++)\n        {\n            if(s[i] == \'R\')\n                nums[i]+=d;\n            else\n                nums[i]-=d;\n        }\n        long long ans= 0;\n        sort(nums.begin() , nums.end());\n        long long prefix =0;\n        for(int i = 0; i <n ; i++)\n        {\n            ans += (i*(long long)nums[i] - prefix);\n            ans %=mod;\n            prefix += nums[i];\n        }\n        return ans;\n        \n    }\n};\n```
['C++']