Tap here to switch tabs
Problem
Submissions

Problem: Movement of Robots

med
30 min
Try to solve the Movement of Robots problem.

Statement

Some robots are placed on a 11 dimensional line. You are given a 00 indexed integer array nums, a string s, and an integer d.

The robot at index i is initially positioned at nums[i] and begins moving in the direction indicated by s[i]. If s[i] is 'L', the robot moves to the left, and if s[i] is 'R', it moves to the right.

Every second, all robots move 11 unit in their current direction. If two robots collide at the same position, both instantly reverse their directions and keep moving.

Return the sum of the distances between all pairs of robots after dd seconds. Since the sum can be large, return it modulo 109+710^9 + 7.

Note:
Robots change direction instantly upon collision without any loss of time. Collisions occur only when robots meet at the exact same position.

Constraints:

  • 2≤2 \le nums.length ≤105\le 10^5

  • −2imes109≤-2 imes 10^9 \le nums[i] ≤2imes109\le 2 imes 10^9

  • 0≤0 \le d ≤109\le 10^9

  • nums.length ==== s.length

  • s consists of 'L' and 'R' only

  • All elements in nums are unique

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Movement of Robots

med
30 min
Try to solve the Movement of Robots problem.

Statement

Some robots are placed on a 11 dimensional line. You are given a 00 indexed integer array nums, a string s, and an integer d.

The robot at index i is initially positioned at nums[i] and begins moving in the direction indicated by s[i]. If s[i] is 'L', the robot moves to the left, and if s[i] is 'R', it moves to the right.

Every second, all robots move 11 unit in their current direction. If two robots collide at the same position, both instantly reverse their directions and keep moving.

Return the sum of the distances between all pairs of robots after dd seconds. Since the sum can be large, return it modulo 109+710^9 + 7.

Note:
Robots change direction instantly upon collision without any loss of time. Collisions occur only when robots meet at the exact same position.

Constraints:

  • 2≤2 \le nums.length ≤105\le 10^5

  • −2imes109≤-2 imes 10^9 \le nums[i] ≤2imes109\le 2 imes 10^9

  • 0≤0 \le d ≤109\le 10^9

  • nums.length ==== s.length

  • s consists of 'L' and 'R' only

  • All elements in nums are unique