FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 2245,3 "name": "destroying-asteroids",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/destroying-asteroids/",6 "date": "2021-12-26",7 "task_description": "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`_._ **Example 1:** ``` **Input:** mass = 10, asteroids = [3,9,19,5,21] **Output:** true **Explanation:** One way to order the asteroids is [9,19,5,3,21]: - The planet collides with the asteroid with a mass of 9. New planet mass: 10 + 9 = 19 - The planet collides with the asteroid with a mass of 19. New planet mass: 19 + 19 = 38 - The planet collides with the asteroid with a mass of 5. New planet mass: 38 + 5 = 43 - The planet collides with the asteroid with a mass of 3. New planet mass: 43 + 3 = 46 - The planet collides with the asteroid with a mass of 21. New planet mass: 46 + 21 = 67 All asteroids are destroyed. ``` **Example 2:** ``` **Input:** mass = 5, asteroids = [4,9,23,4] **Output:** false **Explanation:** The planet cannot ever gain enough mass to destroy the asteroid with a mass of 23. After the planet destroys the other asteroids, it will have a mass of 5 + 4 + 9 + 4 = 22. This is less than 23, so a collision would not destroy the last asteroid. ``` **Constraints:** `1 <= mass <= 105` `1 <= asteroids.length <= 105` `1 <= asteroids[i] <= 105`",8 "test_case": [9 {10 "label": "Example 1",11 "input": "mass = 10, asteroids = [3,9,19,5,21]",12 "output": "true "13 },14 {15 "label": "Example 2",16 "input": "mass = 5, asteroids = [4,9,23,4]",17 "output": "false "18 }19 ],20 "constraints": [21 "1 <= mass <= 105",22 "1 <= asteroids.length <= 105",23 "1 <= asteroids[i] <= 105"24 ],25 "python_template": "class Solution(object):\n def asteroidsDestroyed(self, mass, asteroids):\n \"\"\"\n :type mass: int\n :type asteroids: List[int]\n :rtype: bool\n \"\"\"\n ",26 "java_template": "class Solution {\n public boolean asteroidsDestroyed(int mass, int[] asteroids) {\n \n }\n}",27 "metadata": {28 "func_name": "asteroidsDestroyed"29 }30}