✅ || C++ || Beginner Friendly || Easy to Understand || O(N^3) Time Complexity ||
Complexity\n- ## Time complexity:\n1. The outer loop iterates N times, where N is the number of bombs (for(long long i=0; i<bombs.size(); i++)).\n\n    Time com
# Complexity\n- ## Time complexity:\n1. The outer loop iterates N times, where N is the number of bombs (for(long long i=0; i<bombs.size(); i++)).\n\n    Time complexity: O(N)\n2. Inside the outer loop, there is a while loop that iterates until the    stack is empty.\n\n3. The while loop can potentially iterate N times because each bomb can be visited at most once.\nTherefore, the worst-case time complexity of the while loop is O(N).\n4. Inside the while loop, there is an inner loop that iterates N times (for(long long j=0; j<bombs.size(); j++)).\nTime complexity: O(N)\n5. The total time complexity of the inner loop is O(N), and it is executed O(N) times (inside the while loop).\nTime complexity: O(N^2)\n\nPutting it all together, the overall time complexity is O(N) * O(N^2) = O(N^3).\n\n- ## Space complexity:\n1. The maxBombs variable requires constant space.\n\n2. The visited vector is used to track visited bombs. It has a size equal to the number of bombs, so it requires O(N) space.\n\n3. The s stack is used for the DFS traversal. In the worst case, when all bombs are visited, the stack can store N elements.\n\n4. The space complexity of the s stack is O(N).\nAll other variables used within loops require constant space.\n\nPutting it all together, the overall space complexity is dominated by the space used by the visited vector and the s stack, both of which can grow up to N elements. Therefore, the space complexity of your code is O(N^2), where N is the number of bombs.\n\n# Code\n```\nclass Solution {\npublic:\n    int maximumDetonation(vector<vector<int>>& bombs) {\n        long long maxBombs = 0;\n        for(long long i=0; i<bombs.size(); i++) // O(N)\n        {\n            long long crrIndBombs = 1;\n            \n            vector<long long> visited(bombs.size(), 0); \n            stack<long long> s;\n            s.push(i);\n            visited[i] = 1;\n\n            while(s.size())\n            {\n                long long node = s.top();\n                long long rad = bombs[node][2];\n                long long xCord = bombs[node][0];\n                long long yCord = bombs[node][1];\n                s.pop();\n\n                for(long long j=0; j<bombs.size(); j++)\n                {\n                    if(!visited[j])\n                    {\n                        long long total = ((xCord - bombs[j][0]) * (xCord - bombs[j][0])) + ((yCord - bombs[j][1]) * (yCord - bombs[j][1]));\n                        if (sqrt(total) <= rad){\n                            crrIndBombs++;\n                            s.push(j);\n                            visited[j] = 1;\n                        }\n                    }\n                }\n            }\n\n            maxBombs = max(maxBombs, crrIndBombs);\n        }\n        return maxBombs;\n    }\n};\n```
['C++']