Java | BFS & DFS | With Comments | Easy
The main idea here is to take each bomb and check the number of bombs in its range. \n\nBFS: \n\n\n    public int maximumDetonation(int[][] bombs) {\n        in
The main idea here is to take each bomb and check the number of bombs in its range. \n\n**BFS**: \n\n```\n    public int maximumDetonation(int[][] bombs) {\n        int max = 0;\n        //iterate through each bomb and keep track of max\n        for(int i = 0; i<bombs.length; i++){\n            max = Math.max(max, getMaxBFS(bombs, i));    \n        }\n        return max;\n    }\n    \n   private int getMaxBFS(int[][] bombs, int index){\n        Queue<Integer> queue = new LinkedList<>();\n        boolean[] seen = new boolean[bombs.length];\n        \n        seen[index] = true;\n        queue.offer(index);\n        \n        int count = 1; // start from 1 since the first added bomb can detonate itself\n        \n        while(!queue.isEmpty()){\n            int currBomb = queue.poll();\n            for(int j = 0; j<bombs.length; j++){ //search for bombs to detonate\n                if(!seen[j] && isInRange(bombs[currBomb], bombs[j])){\n                    seen[j] = true;\n                    count++;\n                    queue.offer(j);\n                }\n            }\n        }\n        \n        return count;\n    }\n    \n    //use the distance between two points formula\n    //then check if curr bomb radius is greater than the distance; meaning we can detonate the second bombs\n    private boolean isInRange(int[] point1, int[] point2) {\n        long dx = point1[0] - point2[0], dy = point1[1] - point2[1], radius = point1[2];\n        long distance =  dx * dx + dy * dy;\n        return distance <= radius * radius;\n    }\n```\n\n**DFS**: \n\n```\n    public int maximumDetonation(int[][] bombs) {\n        int max = 0;\n        for (int i = 0; i < bombs.length; i++) {\n            max = Math.max(max, getMaxDFS(i, bombs, new boolean[bombs.length]));\n        }\n        return max;\n    }\n\n    private int getMaxDFS(int index, int[][] bombs, boolean[] seen) {\n        int count = 1;\n        seen[index] = true;\n\n        for (int i = 0; i < bombs.length; i++) {\n            if (!seen[i] && isInRange(bombs[index], bombs[i])) {\n                count += getMaxDFS(i, bombs, seen);\n            }\n        }\n\n        return count;\n    }\n\n    private boolean isInRange(int[] point1, int[] point2) {\n        long dx = point1[0] - point2[0], dy = point1[1] - point2[1], radius = point1[2];\n        long distance = dx * dx + dy * dy;\n        return distance <= radius * radius;\n    }\n```
['Depth-First Search', 'Breadth-First Search', 'Java']