Coordinate With Maximum Network Quality - Problem

You are given an array of network towers towers, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane, and the distance between the two coordinates is the Euclidean distance.

You are also given an integer radius where a tower is reachable if the distance is less than or equal to radius. Outside that distance, the signal becomes garbled, and the tower is not reachable.

The signal quality of the ith tower at a coordinate (x, y) is calculated with the formula ⌊qi / (1 + d)⌋, where d is the distance between the tower and the coordinate. The network quality at a coordinate is the sum of the signal qualities from all the reachable towers.

Return the array [cx, cy] representing the integral coordinate (cx, cy) where the network quality is maximum. If there are multiple coordinates with the same network quality, return the lexicographically minimum non-negative coordinate.

Note: A coordinate (x1, y1) is lexicographically smaller than (x2, y2) if either: x1 < x2, or x1 == x2 and y1 < y2.

Input & Output

Example 1 — Basic Case
$ Input: towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2
Output: [2,1]
💡 Note: At coordinate (2,1): Tower1 distance=√2≈1.41, quality=⌊5/(1+1.41)⌋=2. Tower2 distance=0, quality=⌊7/(1+0)⌋=7. Tower3 distance=1, quality=⌊9/(1+1)⌋=4. Total=2+7+4=13, which is maximum.
Example 2 — Multiple Optimal Points
$ Input: towers = [[23,11,21]], radius = 9
Output: [23,11]
💡 Note: Only one tower, so the coordinate at the tower location (23,11) gives maximum quality: ⌊21/(1+0)⌋=21.
Example 3 — No Signal Case
$ Input: towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 0
Output: [1,2]
💡 Note: With radius=0, only coordinates exactly at tower locations get signal. Tower at (1,2) has highest quality 13, so return [1,2].

Constraints

  • 1 ≤ towers.length ≤ 50
  • towers[i].length == 3
  • 0 ≤ xi, yi, qi ≤ 50
  • 1 ≤ radius ≤ 50

Visualization

Tap to expand
Network Tower Signal Quality ProblemInput: TowersTower 1: (1,2) Q=5Tower 2: (2,1) Q=7Tower 3: (3,1) Q=9Radius = 2Process: Quality CalculationAt coordinate (x,y):distance = √((x-tx)² + (y-ty)²)quality = ⌊qi / (1 + distance)⌋total = sum of all tower qualitiesOutput: Best Coordinate[2, 1]Maximum quality: 13From towers within radiusGrid VisualizationT1T2T3BestQuality at (2,1):Tower1: ⌊5/(1+√2)⌋ = 2Tower2: ⌊7/(1+0)⌋ = 7Tower3: ⌊9/(1+1)⌋ = 4Total = 13🎯 Find coordinate with maximum combined signal quality from all reachable towers
Understanding the Visualization
1
Input
Network towers with positions and quality factors, plus radius
2
Process
Calculate signal quality at each coordinate using distance formula
3
Output
Coordinate with maximum total network quality
Key Takeaway
🎯 Key Insight: The optimal coordinate is usually close to high-quality towers, so we can optimize by only checking coordinates within tower coverage areas.
Asked in
Google 12 Amazon 8 Apple 6
8.9K Views
Medium Frequency
~25 min Avg. Time
245 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen