You are given an array of integers, asteroids, where each element represents an asteroid. The absolute value of an element indicates the size of the asteroid, while the sign indicates its direction: positive means moving to the right, and negative means moving to the left. All asteroids move at the same speed.
When two asteroids collide:
The smaller asteroid is destroyed.
If both are the same size, they both explode.
Asteroids moving in the same direction will never collide.
Your task is to determine the final state of the asteroids after all collisions.
Topics
Companies
Articles
Examples:
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 <= N <= 10^5
-1000 <= asteroids[i] <= 1000
asteroids[i] != 0
Companies:
AmazonMicrosoftAppleVisa
Topics:
Stack
Please log in to access the Submissions tab, where you can review your progress and explore code submissions from other participants.
Please log in to access the Solution tab and view detailed answers and explanations.
Please log in to access the Discussion tab and join conversations with other participants.
Access Restricted: Please Login to access the code editor and test cases.