Robots 🤖 Keep Walking 🚶
intuition :\n\nWhen two Robots meet at some point,\nthey change their directions and continue moving again.\nBut you can assume they don\'t change direction and
**intuition** :\n\nWhen two Robots meet at some point,\nthey change their directions and continue moving again.\nBut you can assume they don\'t change direction and keep moving(since they take 0 unit time).\n\nlet them walk then the question become find the sum of difference between all pair (i , j) of an Array :\n\n\n\n```\nclass Solution {\n\tpublic int sumDistance(int[] nums, String s, int d) {\n        for (int i = 0; i < s.length(); i++) {\n            char dir = s.charAt(i);\n            if (dir == \'R\') {\n                nums[i] += d;\n            } else {\n                nums[i] -= d;\n            }\n        }\n        return sumPairs(nums, nums.length);\n    }\n\n    int sumPairs(int nums[], int n) {\n        Arrays.sort(nums);\n        long sum = 0;\n        int mod = (int) 1e9 + 7;\n        long prefix = 0;\n        for (int i = 0; i < n; i++) {\n            sum = (sum + i * (long) nums[i] - prefix) % mod;\n            prefix += nums[i] % mod;\n        }\n\n        return (int) sum;\n    }\n}\n```\n\n**Similar Problem** : https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank/
['Sorting', 'Java']