Java DFS with memorization, faster than 97%
Basic idea is simmilar to highest voted posts, just optimized a little with caching.\nHere I used a Set for marking visited for simplicity and it can also be re
Basic idea is simmilar to highest voted posts, just optimized a little with caching.\nHere I used a Set for marking visited for simplicity and it can also be reused later, since it contains info about all bombs that will explode if we start at bomb[i].\n\n````\nclass Solution {\n    public int maximumDetonation(int[][] bombs) {\n        int n = bombs.length;\n        int res = 0;\n        Map<Integer, Set<Integer>> cache = new HashMap<>(); \n        for (int i = 0; i < n; i++) {\n            Set<Integer> exploded = new HashSet<>(); \n            dfs(i, bombs, exploded, cache);\n            cache.put(i, exploded);\n            res = Math.max(res, exploded.size());\n        }\n        \n        return res;\n    }\n    \n    private void dfs(int current, int[][] bombs, Set<Integer> visited, Map<Integer, Set<Integer>> cache) {\n        if (cache.containsKey(current)) {\n            visited.addAll(cache.get(current));\n            return;\n        }\n        \n        visited.add(current);\n        int n = bombs.length;\n        for (int i = 0; i < n; i++) {\n            if (!visited.contains(i) && inRange(bombs[current], bombs[i])) {\n                visited.add(i);\n                dfs(i, bombs, visited, cache);\n            }\n        }\n    }\n        \n    private boolean inRange(int[] a, int[] b) {\n        long dx = a[0] - b[0], dy = a[1] - b[1], r = a[2];\n        return dx * dx + dy * dy <= r * r;\n    }\n}\n````
[]