Hello All,
I can't remember the wording of the exact question, but the idea was to generate all contiguous subarrays of a given array. For all contiguous subarrays, find the maximum and minimum, and take their different as a running total of the answer. Return this answer at the end.
Example:
[1,2,3,4]
[1] -> 1 - 1 = 0
[1,2] -> 2-1 = 1
[1,2,3] = 3 - 1 = 2
[1,2,3,4] = 4 - 1 = 3
[2] -> 2 - 2 = 0
[2,3] -> 3 - 2 = 1
[2.3,4] = 4 - 2 = 2
[3] -> 3 - 3 = 0
[3,4] -> 4 - 3 = 1
[4] -> 4 - 4 = 0
The total of all these then is 0 + 1 + 2 + 3 + 0 + 1 + 2 + 1 + 0 = 10
So return 10. Is this a backtracking problem? I'm going to learn backtracking next since I don't know how to do it, which is probably why I couldn't solve it.