Postman Beat Optimal Route Plan
Postman Beat Optimal Route Plan
MediumArrays0% accepted
A postman's beat covers houses numbered around a post office (position 0). To minimize backtracking, he visits all left houses (ascending from leftmost), returns to 0, then visits right houses (ascending from leftmost). Rearrange delivery array optimally.
Approach
Given unsorted house numbers (positive/negative/zero), rearrange to: negative ascending, then zeros, then positive ascending.
Input
6
-5 3 -2 0 4 -1
Output
-5 -2 -1 0 3 4
More Arrays problems
Browse all coding problems →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