i stands at couriers[i] = [x, y] and scooter j sits at scooters[j] = [x, y]. There are at least as many scooters as couriers.
Scooters are handed out step by step. At each step, among all couriers still without a scooter and all scooters still free, take the pair with the smallest Manhattan distance |x1 - x2| + |y1 - y2|; that courier takes that scooter. If several pairs tie, the pair with the smaller courier index wins, and if the courier is the same, the smaller scooter index wins. Keep going until every courier has a scooter.
Return an array answer where answer[i] is the (0-based) index of the scooter courier i ends up with.couriers=[[1, 1], [4, 0]], scooters=[[4, 2], [0, 0]] → [1, 0]
The closest pair is courier 0 with scooter 1 (distance 2). Courier 1 is also at distance 2 from scooter 0, but on a tie the courier with the smaller index goes first. Courier 1 then gets the only scooter left, 0.
couriers=[[2, 2]], scooters=[[0, 2], [2, 0], [5, 5]] → [0]
Scooters 0 and 1 are both at distance 2; the one with the smaller index wins.
couriers=[[0, 0], [0, 5], [6, 6]], scooters=[[0, 4], [0, 1], [9, 9], [6, 3]] → [1, 0, 3]
[x, y] with 0 ≤ x, y < 1000couriers=[[1, 1], [4, 0]], scooters=[[4, 2], [0, 0]]
[1, 0]
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.