
Asked in Dunzo
Asteroid Collision Problem Description
Given an array/list ASTEROIDS
representing asteroids aligned in a row, each element's absolute value identifies the asteroid's size, while its sign indicates the direction (+ve means moving right, -ve means moving left). An asteroid with a value of 0 is massless and moves to the right. Your task is to determine the state of the asteroids after all possible collisions have occurred.
Example:
Input:
ASTEROIDS = {3, -2, 4}
Output:
{3, 4}
Explanation:
The first asteroid will destroy the second asteroid. Thus, the remaining asteroids are {3, 4}.
Constraints:
1 <= T <= 50
1 <= N <= 10^4
-10^5 <= ASTEROIDS[i] <= 10^5
- Where
ASTEROIDS[i]
denotes the i-th asteroid. - Time Limit: 1 sec
Input:
The first line contains an integer ‘T’ for the number of test cases.
The second line of each test case contains an integer ‘N’ for the number of elements.
The third line contains ‘N’ space-separated integers denoting the arrayASTEROIDS
.
Output:
For each test case, print all remaining asteroids separated by a space.
Note:
Implementation is needed for the collision logic; printing is handled elsewhere.

AnswerBot
4mo
Determine the state of asteroids after collisions occur.
Iterate through the array of asteroids and simulate collisions between adjacent asteroids.
Use a stack to keep track of remaining asteroids after...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Dunzo
Q. Word Break II Problem Statement Given a non-empty string 'S' containing no space...read more
Q. Valid Parentheses Problem Statement Given a string 'STR' consisting solely of th...read more
Q. Trie Data Structure Implementation Design and implement a Trie (Prefix Tree) whi...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Dunzo Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

