Detonate the Maximum Bombs
Updated
Problem statement
You are given a list of bombs. Each bomb is given as bombs[i] = [x_i, y_i, r_i]: the bomb lies at point (x_i, y_i) on a flat plane, and its range is the circle around that point with radius r_i.
When a bomb goes off, it sets off every other bomb whose location is inside its range or exactly on the edge of the circle. Each of those bombs then sets off the bombs in its own range, and so on, until no new bomb goes off.
You may set off exactly one bomb yourself. Return the largest number of bombs that can go off in total, counting the one you set off.
Function
maximumDetonation(bombs: int[][]) → intExamples
Example 1
bombs = [[1,1,3],[4,1,1],[4,5,4],[8,5,2],[10,5,1]]return = 4Set off bomb 2 at (4, 5) with radius 4. Bomb 1 at (4, 1) is 4 away, exactly on the edge, and bomb 3 at (8, 5) is 4 away, so both go off. Bomb 3 has radius 2 and bomb 4 at (10, 5) is 2 away, so bomb 4 goes off too. Bomb 0 at (1, 1) is 5 away from bomb 2 and out of reach of bombs 1, 3 and 4, so it stays. That is 4 bombs, and no other first bomb does better.
Example 2
bombs = [[2,2,1],[5,6,5]]return = 2The bombs are 5 apart. Bomb 1 has radius 5, so bomb 0 is on the edge of its range: setting off bomb 1 sets off both. Bomb 0 has radius 1 and cannot reach bomb 1, so starting there gives only 1. The answer is 2.
Example 3
bombs = [[1,1,1],[10,10,2],[20,1,3]]return = 1No bomb is inside another bomb's range, so only the bomb you set off goes off. The answer is 1.
Constraints
1 <= bombs.length <= 100bombs[i].length == 31 <= x_i, y_i, r_i <= 10^5
More Zomato / Eternal interview questions
- Friend Circles and Redundant ConnectionsPHONE SCREEN · Seen Sep 2026
- Find the Two Unique NumbersONSITE INTERVIEW · Seen Oct 2026
- Flipping MatrixONSITE INTERVIEW · Seen Oct 2026
- Jump Game IVONSITE INTERVIEW · Seen Oct 2026
- LFU CacheONSITE INTERVIEW · Seen Aug 2026
- Maximum Production Within PowerOA · Seen Jul 2026
- Rearrange Songs by AuthorOA · Seen Jul 2026
- Robot Warehouse OptimizationOA · Seen Jul 2026
- Special KeyboardONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Detonate Bombs with Chain ReactionsAirbnb · PHONE SCREENAirbnb interview questions
- Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
- Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
- Count Connected Point ClustersGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
- Maximum Area of IslandSkydio · PHONE SCREENSkydio interview questions
- Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
- Max Area of IslandGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Max Area of IslandRoku · ONSITE INTERVIEWRoku interview questions
- Max Area of IslandBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions