⌘K
Flycodx

Ambulance Optimal Route Grid Dispatch

Ambulance Optimal Route Grid Dispatch

HardArrays100% accepted

Pune's emergency dispatch center receives multiple accident alerts simultaneously across the city. Given hospital and incident coordinates on a city grid, find the minimum total distance ambulances must travel collectively. Rule: each incident is served by its nearest hospital (Manhattan distance). Return the total distance over all incidents. Your solve(...) function receives the inputs as ready-made arguments — no input reading or parsing needed; just return the answer.

Approach

Given hospital positions and incident coordinates in 2D grid, find minimum total Manhattan distance.

Input

hospitals=[[0,0],[5,5]] incidents=[[2,2],[3,3]]

Output

8
solution.py
Loading editor...
Test 1
Test 2
Test 3

Press Run to test your custom input, or Submit to judge against all test cases.

Sign in to continue

Create a free account to run code, submit solutions and track progress.

  • Free forever — no credit card
  • 10+ languages with live execution
  • Points, streaks & leaderboards
Auto Save OnLn 1, Col 1Spaces: 4UTF-8LFPython 3