Ctrl K

Longest Firework Chain

Medium
Firework charges are laid out on a square. Charge charges[i] = [x, y, r] sits at point (x, y), and its burst ignites everything inside the circle of radius r around that point, boundary included. When a charge goes off, it ignites every charge within its circle, those ignite the charges within theirs, and so on. Note that A reaching B does not mean B reaches A. You light exactly one charge. Return the largest number of charges that can end up going off, the first one included.
Example 1
charges=[[2, 2, 5], [6, 2, 3], [9, 2, 3]] → 3

Charge 0 reaches charge 1 (distance 4), which in turn reaches charge 2 (distance 3), so all three go off. Starting from charge 2 only sets off charge 1, whose radius falls short of charge 0.

Example 2
charges=[[1, 1, 1], [10, 10, 1]] → 1

The charges are too far apart, so only the one you light goes off.

Constraints
  • 1 ≤ len(charges) ≤ 100
  • len(charges[i]) == 3
  • 0 ≤ x, y ≤ 10⁵
  • 1 ≤ r ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAcross the Park Around the Ponds HardRatio Chain Queries MediumShortest Path of a Rolling Ball MediumRooms Open from the Hall MediumTreasure Gates Race Medium
loading Python…
Input
charges=[[2, 2, 5], [6, 2, 3], [9, 2, 3]]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.