Trains the technique from
LeetCode 2126Destroying AsteroidsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A snowball of weight mass is set rolling past a line of clumps whose weights are given as asteroids. The clumps may be taken in any order you like.
The snowball takes a clump only when its own weight is at least that clump's weight, and taking it adds the clump's weight to the snowball. Meeting a clump heavier than the snowball ends the run.
Return true when some order lets the snowball take every clump.
Example 1
Going lightest first, the snowball reaches 22, then 31, then 54, then 95, then 157, and nothing was ever too heavy for it.
Example 2
Taking the 1 first brings the snowball to 3, which is not enough for the 4, so the run cannot be completed. Note that with a 4 it would have reached 7 and then managed the 9, so the order matters.
Example 3
Each clump exactly matches the weight the snowball has reached, and matching is enough, so it doubles its way through all five.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def asteroids_destroyed(mass: int, asteroids: list[int]) -> bool:public boolean asteroidsDestroyed(int mass, int[] asteroids)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.