You are viewing a single comment's thread. Return to all comments →
If I understand your question, you are asking why the need to run the algorithm twice, once forward and once in reverse.
The reason for the need to check the reverse case is in the definition of the problem. The requirements are that the array is sorted such the sum of the differences between each two consecutive numbers is minimized. There are two ways to acheive that goal -- ascending and descending sorting the list. The descending sort is the "reverse" in this case.