⌘K
Flycodx

Shortest Multi-Zone Delivery Route

Shortest Multi-Zone Delivery Route

HardArrays100% accepted

Zomato delivery executive Priya must collect food from at least one restaurant in each zone before delivering to customer. Given zone coordinates and delivery location, find shortest route visiting minimum one restaurant per zone. Rule: pick exactly one restaurant per zone; visit them in zone order (zone 1 first), then the delivery point. Distance is Manhattan. Return the minimum total distance. Your solve(...) function receives the inputs as ready-made arguments — no input reading or parsing needed; just return the answer.

Approach

Start at the delivery point and visit at least one coordinate from EACH zone (any order). Return the minimum total Manhattan distance travelled (sum of |dx|+|dy| between consecutive stops; no return to start). solve(zones, delivery).

Input

zones=[[[0,0],[1,1]],[[5,0]],[[5,5]]] delivery=[3,3]

Output

14
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