Coordinate With Maximum Network Quality — LeetCode 1620 Python Solution
MediumArrayEnumeration
- Problem
- #1620
- Reading time
- 3 min
- Source
- leetcode.com
The 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.
Example
- Input
- towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2
- Output
- [2,1]
- Explanation
- At coordinate (2, 1) the total quality is 13.
Python solution
Python
class Solution:
def bestCoordinate(self, towers: List[List[int]], radius: int) -> List[int]:
mx = 0
ans = [0, 0]
for i in range(51):
for j in range(51):
t = 0
for x, y, q in towers:
d = ((x - i) ** 2 + (y - j) ** 2) ** 0.5
if d <= radius:
t += floor(q / (1 + d))
if t > mx:
mx = t
ans = [i, j]
return ansComplexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1) to O(n) auxiliary |
Related problems
LeetCode 1534Count Good TripletsEasyLeetCode 1566Detect Pattern of Length M Repeated K or More TimesEasyLeetCode 2735Collecting ChocolatesMediumLeetCode 2765Longest Alternating SubarrayEasyLeetCode 2778Sum of Squares of Special ElementsEasyLeetCode 2934Minimum Operations to Maximize Last Elements in ArraysMedium
Frequently asked questions
- How hard is LeetCode 1620. Coordinate With Maximum Network Quality?
- LeetCode 1620. Coordinate With Maximum Network Quality is rated Medium on LeetCode.
- What topics does LeetCode 1620. Coordinate With Maximum Network Quality cover?
- LeetCode 1620. Coordinate With Maximum Network Quality is tagged Array and Enumeration on LeetCode.