changes holds day-by-day changes of a price. The swing of a stretch of days is the absolute value of the sum of changes over that stretch (a stretch is a contiguous part of the array, possibly empty; an empty stretch has a swing of 0).
Return the largest swing over all stretches, whether it is a rise or a fall.changes=[3, -7, 2, -6, 4] → 11
The stretch [-7, 2, -6] sums to -11, whose absolute value is 11. No stretch does better.
changes=[5, 1, -2, 6] → 10
The whole array: 5 + 1 - 2 + 6 = 10.
changes=[0, 0] → 0
changes=[3, -7, 2, -6, 4]
11
Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.