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.
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
mass = 10, asteroids = [3,9,19,5,21]
true
# Example 2
mass = 5, asteroids = [4,9,23,4]
false
Constraints
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.