Skip to content

Practice Destroying Asteroids

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2126
LeetCode Problem

Destroying Asteroids

Problem Statement

You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the ith asteroid. You can arrange for the planet to collide with the asteroids in any arbitrary order. If the mass of the planet is greater than or equal to the mass of the asteroid, the asteroid is destroyed and the planet gains the mass of the asteroid. Otherwise, the planet is destroyed. Return true if all asteroids can be destroyed. Otherwise, return false.

Source: Destroying Asteroids on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
mass = 10, asteroids = [3,9,19,5,21]
Output
true

# Example 2

Input
mass = 5, asteroids = [4,9,23,4]
Output
false

Constraints

1 <= mass <= 10^5
1 <= asteroids.length <= 10^5
1 <= asteroids[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Destroying Asteroids.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.