Beats 100%🔥|| Java Easy Code✅|| Beginner Friendly✅✅|| Sorting✅
\n# Complexity\n- Time complexity: O(NlogN)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) 
\n# Complexity\n- Time complexity: $$O(NlogN)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    static int mod = (int)(1e9 + 7);\n\n    public int sumDistance(int[] nums, String s, int d) {\n        for(int i = 0 ; i < nums.length ; i++){\n            if(s.charAt(i) == \'R\') nums[i] += d;\n            else nums[i] -= d;\n        }\n    Arrays.sort(nums);\n\n    long sum = 0;\n    long prefixsum = 0;\n\n    for(int i = 0 ; i < nums.length ;i++){\n        sum = (sum + i*(long)nums[i] - prefixsum)%mod;\n        prefixsum += nums[i]%mod;\n    }\n\n    return (int)sum;\n    }\n}\n```
['Sorting', 'Java']