Tap here to switch tabs
Problem
Submissions

Problem: Nearest Available Drone

Try to solve the Nearest Available Drone problem.

Statement

You are given a 2extD2 ext{D} integer array drones, where drones[i] = [x_i, y_i, range_i] represents the coordinates (xi,yi)(x_i, y_i) and the maximum operating range range_i of the iextthi^{ ext{th}} drone. You are also given an integer array target = [tx, ty] representing the coordinates of a target.

The Manhattan distance between a drone at (xi,yi)(x_i, y_i) and the target at (tx,ty)(tx, ty) is calculated as ∣xi−tx∣+∣yi−ty∣|x_i - tx| + |y_i - ty|. A drone can reach the target if the Manhattan distance between them is less than or equal to its range_i.

Return the index of the drone that can reach the target with the minimum Manhattan distance. If there is a tie, return the smallest index. If no drone can reach the target, return −1-1.

Constraints:

  • 1≤1 \leq drones.length ≤100\leq 100

  • drones[i].length =3= 3

  • target.length =2= 2

  • −25≤xi,yi,tx,ty≤25-25 \leq x_i, y_i, tx, ty \leq 25

  • 1≤rangei≤1001 \leq range_i \leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Nearest Available Drone

Try to solve the Nearest Available Drone problem.

Statement

You are given a 2extD2 ext{D} integer array drones, where drones[i] = [x_i, y_i, range_i] represents the coordinates (xi,yi)(x_i, y_i) and the maximum operating range range_i of the iextthi^{ ext{th}} drone. You are also given an integer array target = [tx, ty] representing the coordinates of a target.

The Manhattan distance between a drone at (xi,yi)(x_i, y_i) and the target at (tx,ty)(tx, ty) is calculated as ∣xi−tx∣+∣yi−ty∣|x_i - tx| + |y_i - ty|. A drone can reach the target if the Manhattan distance between them is less than or equal to its range_i.

Return the index of the drone that can reach the target with the minimum Manhattan distance. If there is a tie, return the smallest index. If no drone can reach the target, return −1-1.

Constraints:

  • 1≤1 \leq drones.length ≤100\leq 100

  • drones[i].length =3= 3

  • target.length =2= 2

  • −25≤xi,yi,tx,ty≤25-25 \leq x_i, y_i, tx, ty \leq 25

  • 1≤rangei≤1001 \leq range_i \leq 100