Ctrl K

Strongest Signal Spot

Medium
Antennas stand on a grid map: antennas[i] = [x, y, q] is an antenna at (x, y) with power q. Distance is the usual Euclidean distance. An antenna is picked up at a point if its distance d from that point is at most reach. It then contributes a signal of ⌊q / (1 + d)⌋ there (division rounded down). Antennas farther than reach contribute nothing. The connection strength at a point is the sum of the signals of all antennas picked up there. Find the point with non-negative integer coordinates where the connection strength is the highest and return it as [x, y]. If several points tie, return the smallest one: the smaller x, and for equal x the smaller y.
Example 1
antennas=[[2, 3, 12], [4, 3, 8]], reach=2 → [2, 3]

At (2, 3) the first antenna gives ⌊12 / 1⌋ = 12 and the second, 2 away, gives ⌊8 / 3⌋ = 2, for 14 in total. At (3, 3) it would be only 6 + 4 = 10.

Example 2
antennas=[[0, 4, 6], [4, 0, 6]], reach=1 → [0, 4]

Both (0, 4) and (4, 0) get a signal of 6; we pick the smaller point, (0, 4).

Example 3
antennas=[[7, 9, 0]], reach=5 → [0, 0]

The antenna is switched off, the signal is 0 everywhere, so the answer is (0, 0).

Constraints
  • 1 ≤ len(antennas) ≤ 50
  • antennas[i].length == 3
  • 0 ≤ x, y, q ≤ 50
  • 1 ≤ reach ≤ 50
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrimes Below a Bound MediumLongest Ridge on the Route MediumLatest Clock From Digits MediumFlanking Move on the Board MediumA Word in a Crossword Slot Medium
loading Python…
Input
antennas=[[2, 3, 12], [4, 3, 8]], reach=2
Expected
[2, 3]

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