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
However, there's a catch! Towers have a limited
Your Goal: Find the integral coordinate
Think of it like finding the sweet spot where your phone gets the best combined signal from all nearby cell towers!
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
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.
โ Linear Growth
Space Complexity
O(1)
Only storing the current best coordinate and quality value
โ 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โ)ยฒ]
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code