nearest-available-drone.py (586B)
1 def drone_distance(drone, target): 2 return abs(drone[0] - target[0]) + abs(drone[1] - target[1]) 3 4 class solution: 5 def nearestdrone(self, drones: list[list[int]], target: list[int]) -> int: 6 # <= manhattan 7 min_index = -1 8 min_distance = -1 9 10 for idx in range(len(drones)): 11 drone = drones[idx] 12 distance = drone_distance(drone, target) 13 if distance <= drone[2] and (min_index == -1 or min_distance > distance): 14 min_index = idx 15 min_distance = distance 16 17 return min_index