Create a list of tuples where each tuple contains the position, health, and direction of a robot, and the original index.
Sort the list of tuples based on the position of the robots.
Initialize an empty stack to keep track of robots that may collide.
Iterate through the sorted list of robots:
a. If the current robot is moving to the right, push its index onto the stack.
b. If the current robot is moving to the left, check the top of the stack:
i. If the stack is empty, continue to the next robot.
ii. If the stack is not empty, compare the health of the top robot with the current robot.
iii. If the current robot has higher health, pop the top robot and decrease the current robot's health by 1.
iv. If the health is equal, pop the top robot and mark the current robot's health as 0 (remove it).
v. If the current robot has lower health, mark its health as 0 (remove it) and continue to the next robot.
After the iteration, filter out the robots with health greater than 0 and sort them based on their original index.
Return the health of the surviving robots in the order of their original indices.