⌘K
Flycodx

Postman Beat Traffic Weighted Path

Postman Beat Traffic Weighted Path

HardArrays100% accepted

Ravi is a postman covering a beat area in Pune with N houses. Roads between houses have varying traffic weights. Find the minimum weighted distance to visit all houses and return to start. Rule: weights[i][j] is the road cost between houses i and j. Start at house 0, visit every house exactly once, return to house 0. Return the minimum total cost (n <= 6). Your solve(...) function receives the inputs as ready-made arguments — no input reading or parsing needed; just return the answer.

Approach

Given an array of house positions with traffic weights, find the minimum weighted path visiting all houses.

Input

n=3 weights=[[0,2,3],[2,0,2],[3,2,0]]

Output

7
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