JAVA || Easy Explanation
Intuition\nDon\'t think about directions.\n1. Just add d in nums[i] if R ,\n2. otherwise subtract d from nums[i]\n3. and add differenc of each.\n\nThis are simp
# Intuition\nDon\'t think about directions.\n1. Just add d in nums[i] if R ,\n2. otherwise subtract d from nums[i]\n3. and add differenc of each.\n\nThis are simple Steps but Calculation of difference sum is main part.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nAfter moving all the steps d time take sum:\n1. Sort the array so u will get correct difference sum.\n\nExaplaination ---------------------------\nIt is like a1+a2+a3 ->\n (a1-a2) + (a1-a3) + (a2-a3) => 2 * a1 + 0 * a2 + (-2) * a3\n\nDifference is so simple to calculate with above ,if u observe.\n .---------------------------------------------------------------\n\n2. So from above we can say it is multiple of (length of nums minus 1)\ndecrease it by 2 in each iteration for each term of equation.\n3. Take mod in each step .\n4. Remember to take a long var to store ans and typecast it at last.\n   \n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(nlog(n))\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 {\n    final int mod = 1_000_000_007;\n    public int sumDistance(int[] nums, String s, int d) {\n        \n        for(int i=0;i<nums.length;i++){\n            if(s.charAt(i)==\'R\'){\n                nums[i]+=d;\n            }else{\n                nums[i]-=d;\n            }\n        }\n        long ans=0;\n        int n=nums.length-1;\n        Arrays.sort(nums);\n        for(int i=0;i<nums.length;i++){\n            ans+=((n)*(long)nums[i]);\n            ans%=mod;\n            n-=2;\n        }\n        return (int) -ans%mod;\n    }\n}\n```
['Java']