Compute the total number of steps needed to visit trees placed along a road in order.
Roadside Trees
gfgA road has several trees planted at different positions along a straight line. You start at the first tree and move to the next tree in the given order. To go from one tree to the next, you need to walk the absolute distance between their positions.
Your task is to calculate the total distance walked while visiting all trees in order.
This is the simplified version of the problem, where the tree positions are already given in the order you must visit them.
Example 1
Input
5 1 5 2 8 3
Output
14
Explanation
The distances are |5-1| = 4, |2-5| = 3, |8-2| = 6, and |3-8| = 5. The total is 4 + 3 + 6 + 5 = 18.
(Note: for this illustrative example, the output should match the sum of consecutive absolute differences.)
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.