O(N) C# Monotonic Stack
Intuition\nApart from O(NLogN) approach which involves sorting, this problem can also be solved in O(N) \n\n# Approach\nThis approach involves monotonic stack.\
# Intuition\nApart from O(NLogN) approach which involves sorting, this problem can also be solved in O(N) \n\n# Approach\nThis approach involves monotonic stack.\nKeep adding asteroid which cannot be destroyed at present in the stack.\nAs soon as an asteroid which can be destroyed (mass less than or equal to planet mass), we add it to the planet mass.\nKeep checking for all the elements in the stack.\n\nUsed long for newMass to avoid overflow, as we are adding up integers.\n\n# Complexity\n\n- Time complexity:\nO(N)\n- Space complexity:\nO(N)\n\n# Code\n```\npublic class Solution {\n    public bool AsteroidsDestroyed(int mass, int[] asteroids) {\n\n        Stack<int> stack = new();\n        long newMass = mass;\n \n        for(int i = 0; i < asteroids.Length; i++)\n        { \n            stack.Push(asteroids[i]);\n            while(stack.Count > 0 && stack.Peek() <= newMass)\n            {\n                newMass += stack.Pop();\n            } \n        }\n\n        return stack.Count > 0 ? false : true;\n    }\n}\n```
['Monotonic Stack', 'C#']