FastPrepAsteroid Collision
Problems/Asteroid Collision

Asteroid Collision

Zscaler logoZscaler● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report says the task was similar to Asteroid Collision but does not keep the changed rules, the interface, or the limits. Our version is the usual Asteroid Collision task and is about 48% the same as the reported question.

You are given an integer array asteroids representing asteroids in a row. Absolute value is size, and sign is direction: positive moves right and negative moves left. All asteroids move at the same speed.

When two asteroids moving toward each other collide, the smaller one explodes. If their sizes are equal, both explode. Asteroids moving in the same direction never collide.

Return the asteroids remaining after every collision, in original left-to-right order.

Function

asteroidCollision(asteroids: int[]) → int[]

Examples

Example 1

asteroids = [5,10,-5]return = [5,10]

Asteroid 10 destroys -5; 5 never collides.

Example 2

asteroids = [8,-8]return = []

The approaching asteroids have equal size, so both explode.

Example 3

asteroids = [10,2,-5]return = [10]

-5 destroys 2, then 10 destroys -5.

Constraints

  • 1 <= asteroids.length <= 100000
  • -10^9 <= asteroids[i] <= 10^9
  • asteroids[i] != 0

More Zscaler interview questions

  • Check Whether a Byte Is NonzeroONSITE INTERVIEW · Seen Sep 2024
  • Count Vowel PermutationsONSITE INTERVIEW · Seen Sep 2024
  • Longest Common Subsequence LengthONSITE INTERVIEW · Seen Jun 2024
  • Run-Length EncodingONSITE INTERVIEW · Seen Jun 2024
  • Rate Limiter with Hourly and Daily Effort QuotasPHONE SCREEN · Seen Jul 2026
  • Merging PalindromesPHONE SCREEN · Seen Sep 2024
  • Find the Element With Odd FrequencyPHONE SCREEN · Seen Jun 2024
  • Merge IntervalsPHONE SCREEN · Seen Jun 2024
  • Sum of Divisors of the Array GCDPHONE SCREEN · Seen Jun 2024
  • How Many Sentences? 🌿OA · Seen Mar 2024

Similar questions at other companies

  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
  • Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Surviving Balls after Directional CollisionsSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Render a Comment HierarchyAmazon · ONSITE INTERVIEW
  • Asteroid CollisionAdobe · ONSITE INTERVIEWAdobe interview questions
  • Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
  • Asteroid CollisionBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Exclusive Time of FunctionsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Implement Stack Push and Pop OperationsLSEG · ONSITE INTERVIEWLSEG interview questions

Interview reports that mention this question

  • Zscaler SDE C++ and OS Rounds: 7 Experiences (Part 2 of 6)
  • Zscaler Campus SDE Interviews: 37 Experiences (Part 1 of 6)

Zscaler interview experiences

  • Zscaler Campus Drive Interviews: 4 Experiences (Part 6 of 6)
  • Zscaler Java, QA and Cloud Rounds: 8 Experiences (Part 5 of 6)
  • Zscaler UI and DevTest Rounds: 8 Experiences (Part 4 of 6)
  • Zscaler Intern, QA and SRE Rounds: 7 Experiences (Part 3 of 6)
All Zscaler interview questionsSee Zscaler hiring insights
Saved
class Solution {
    public int[] asteroidCollision(int[] asteroids) {
      // write your code here
    }
}
Checking account…