Initialize an empty stack to store the asteroids that are still in motion.
Iterate over each asteroid in the input list.
a. If the current asteroid is moving to the right, push it onto the stack.
b. If the current asteroid is moving to the left, compare it with the top of the stack:
i. If the stack is empty or the top of the stack is moving to the left, push the current asteroid onto the stack.
ii. If the top of the stack is moving to the right, compare their sizes:
- If the current asteroid is larger, pop the top of the stack and continue comparing with the new top.
- If they are equal, pop the top of the stack and discard the current asteroid.
- If the current asteroid is smaller, discard it.
After processing all asteroids, the stack contains the remaining asteroids in reverse order.
Convert the stack to a list in the correct order and return it.