Coordinate With Maximum Network Quality - Problem
Network Tower Signal Optimization Problem

Imagine you're a network engineer tasked with finding the optimal location to place a monitoring station that receives the maximum combined signal quality from all nearby network towers.

You are given an array of network towers towers, where towers[i] = [xi, yi, qi] represents the i-th network tower located at coordinates (xi, yi) with a quality factor qi. Each tower broadcasts a signal that weakens with distance according to the formula: โŒŠqi / (1 + d)โŒ‹, where d is the Euclidean distance from the tower to your position.

However, there's a catch! Towers have a limited radius - if the distance exceeds this radius, the signal becomes completely garbled and unusable.

Your Goal: Find the integral coordinate [cx, cy] where the total network quality (sum of all reachable tower signals) is maximized. If multiple coordinates tie for the maximum, return the lexicographically smallest coordinate.

Think of it like finding the sweet spot where your phone gets the best combined signal from all nearby cell towers!

Input & Output

example_1.py โ€” Basic Case
$ Input: towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2
โ€บ Output: [2,1]
๐Ÿ’ก Note: At coordinate (2,1): Tower 1 is at distance โˆš2 โ‰ˆ 1.41, contributing โŒŠ5/(1+1.41)โŒ‹ = 2 quality. Tower 2 is at distance 0, contributing โŒŠ7/(1+0)โŒ‹ = 7 quality. Tower 3 is at distance 1, contributing โŒŠ9/(1+1)โŒ‹ = 4 quality. Total = 13 quality, which is maximum.
example_2.py โ€” Out of Range
$ Input: towers = [[23,11,21]], radius = 9
โ€บ Output: [23,11]
๐Ÿ’ก Note: Only one tower exists, so the optimal position is exactly at the tower location (23,11) where we get maximum signal quality of โŒŠ21/(1+0)โŒ‹ = 21.
example_3.py โ€” No Reachable Towers
$ Input: towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2
โ€บ Output: [1,2]
๐Ÿ’ก Note: Multiple coordinates might have the same maximum quality. We return the lexicographically smallest one. At (1,2), we get quality 13 from the first tower, plus contributions from other towers within radius 2.

Visualization

Tap to expand
Network Tower Signal OptimizationTower 1Q=5Tower 2Q=7Tower 3Q=9โ˜… Optimaldโ‚โ‰ˆ1.4dโ‚‚โ‰ˆ3.2dโ‚ƒโ‰ˆ4.1Signal Quality Calculation at Optimal Point (350, 180)Tower 1: โŒŠ5/(1+1.4)โŒ‹ = โŒŠ2.08โŒ‹ = 2Tower 2: โŒŠ7/(1+3.2)โŒ‹ = โŒŠ1.67โŒ‹ = 1Tower 3: Distance > radius, not reachableTotal Quality = 2 + 1 + 0 = 3Colored circles show tower coverage areas. The optimal point maximizes combined signal strength.
Understanding the Visualization
1
Map the Territory
Identify all tower locations and their coverage areas (circles with given radius)
2
Define Search Zone
Create a bounding box that encompasses all possible optimal locations
3
Systematic Search
Check each integral coordinate and calculate total signal quality from reachable towers
4
Find the Sweet Spot
Select the coordinate with maximum quality (lexicographically smallest for ties)
Key Takeaway
๐ŸŽฏ Key Insight: The optimal location is always within the radius of at least one tower, so we can limit our search to a bounded area around all towers rather than the infinite coordinate plane.

Time & Space Complexity

Time Complexity
โฑ๏ธ
O(W ร— H ร— N)

W and H are the width and height of the search space, N is the number of towers. For each coordinate, we check all towers.

n
2n
โœ“ Linear Growth
Space Complexity
O(1)

Only storing the current best coordinate and quality value

n
2n
โœ“ Linear Space

Constraints

  • 1 โ‰ค towers.length โ‰ค 50
  • towers[i].length == 3
  • 0 โ‰ค xi, yi, qi โ‰ค 50
  • 1 โ‰ค radius โ‰ค 50
  • All coordinates are integers
  • Distance is calculated using Euclidean formula: โˆš[(xโ‚‚-xโ‚)ยฒ + (yโ‚‚-yโ‚)ยฒ]
Asked in
Amazon 35 Google 28 Microsoft 22 Meta 18
28.5K Views
Medium Frequency
~18 min Avg. Time
742 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