Explanation
To solve this problem you need to do this thing:
- Sort the input.
- Sum the distance between x1 > x2, x2 > x3, and so on.
- Then multiply it by 2 (Round-Trip).
Optimization
There's much simpler solution for this problem that does not include sorting. Just calculate the min and max while you read the input. Then find the min - max difference and multiply it by 2.
Source Code
Tidak ada komentar:
Posting Komentar