Tap here to switch tabs
Problem
Submissions

Problem: Destroying Asteroids

med
30 min
Try to solve the Destroying Asteroids problem.

Statement

You are given an integer mass, which represents the initial mass of a planet. You are also given an integer array asteroids, where asteroids[i] is the mass of the iextthi^{ ext{th}} asteroid.

You can choose the order in which the planet collides with the asteroids. If the planet’s mass is greater than or equal to the mass of the colliding asteroid, the asteroid is destroyed, and the asteroid’s mass is added to the planet’s total mass. Otherwise, the planet is destroyed.

Return true if all asteroids can be destroyed, or false otherwise.

Constraints:

  • 1≤1 \leq mass ≤105\leq 10^5

  • 1≤1 \leq asteroids.length ≤105\leq 10^5

  • 1≤1 \leq asteroids[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Destroying Asteroids

med
30 min
Try to solve the Destroying Asteroids problem.

Statement

You are given an integer mass, which represents the initial mass of a planet. You are also given an integer array asteroids, where asteroids[i] is the mass of the iextthi^{ ext{th}} asteroid.

You can choose the order in which the planet collides with the asteroids. If the planet’s mass is greater than or equal to the mass of the colliding asteroid, the asteroid is destroyed, and the asteroid’s mass is added to the planet’s total mass. Otherwise, the planet is destroyed.

Return true if all asteroids can be destroyed, or false otherwise.

Constraints:

  • 1≤1 \leq mass ≤105\leq 10^5

  • 1≤1 \leq asteroids.length ≤105\leq 10^5

  • 1≤1 \leq asteroids[i] ≤105\leq 10^5