positions[i] is the starting coordinate of robot i (all coordinates are distinct). The string directions says where each robot heads once the command is given: L toward smaller coordinates, R toward larger ones. Every robot moves at one unit per second.
Whenever two robots end up at the same point, they instantly turn around and keep going in opposite directions. A meeting can happen mid-unit too: robots at 0 and 1 heading toward each other bounce off after half a second and are back at 0 and 1 half a second later.
Return the sum of distances over all pairs of robots seconds seconds after the command. Count each pair once. The answer can be large, so return it modulo 10⁹ + 7.positions=[0, 5], directions="RL", seconds=1 → 3
After one second the robots stand at 1 and 4, which are 3 apart.
positions=[-1, 1, 4], directions="RLR", seconds=2 → 14
After one second the first two robots meet at 0 and turn around; one second later they are at -1 and 1. The third robot is at 6. The pairwise distances add up to 2 + 7 + 5 = 14.
L and R onlypositions=[0, 5], directions="RL", seconds=1
3
Run checks the first 3 tests in your browser. Submit checks all 102 tests on the server, hidden ones included.