Very Easy For loop solution || C++ || Beats 96% in time || Beats 92% in memory
Approach\nWe just have to sort the array and check according to the given conditions. Also make the type of mass as long long else it will result in overflow.\n
# Approach\nWe just have to sort the array and check according to the given conditions. Also make the type of mass as long long else it will result in overflow.\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    bool asteroidsDestroyed(long long mass, vector<int>& asteroids) {\n        int c=0;\n        sort(asteroids.begin(),asteroids.end());\n        for(int i=0;i<asteroids.size();i++){\n            if(asteroids[i]<=mass){\n                c++;\n                mass+=asteroids[i];\n            } \n            else break;\n        }\n        if(c==asteroids.size())return 1;\n        else return 0;\n    }\n};\n```
['C++']