n robots stand on a straight rail. Robot i is at point spots[i], has power[i] units of durability and faces heading[i], which is 'L' (left) or 'R' (right). All points are distinct, but the arrays are not necessarily sorted by position.
All robots start moving in their directions at the same moment and at the same speed. When two robots end up at the same point, they collide:
- the one with less durability is knocked out, and the other loses 1 unit of durability and keeps moving in the same direction;
- if their durability is equal, both are knocked out.
Once no more collisions can happen, return the durability of the surviving robots in the order the robots appear in the input. If none survive, return an empty list.spots=[8, 2, 5], power=[4, 6, 3], heading="LRR" → [5]
Robot 0 (at 8) heads left and first meets robot 2 (at 5): 4 > 3, so robot 2 is out and robot 0 drops to 3. Next it meets robot 1: 6 > 3, so robot 0 is out and robot 1 drops to 5.
spots=[1, 3, 7, 9], power=[5, 5, 2, 8], heading="RLLR" → [2, 8]
Robots 0 and 1 meet with equal power and both drop out. Robot 2 drives off to the left and robot 3 to the right, with nobody in their way.
spots=[4, 10], power=[7, 9], heading="LR" → [7, 9]
The robots move apart and never meet.
spots=[8, 2, 5], power=[4, 6, 3], heading="LRR"
[5]
Run checks the first 3 tests in your browser. Submit checks all 138 tests on the server, hidden ones included.