Given an list of integers, return the largest gap summation between elements of that list.
Here's an illustrative example. Consider the list:
[9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5]
which, sorted (for human readability), becomes
[0, 0, 4, 5, 5, 6, 9, 20, 25, 26, 26]
we can now see that the largest gap in the list is the gap between 9 and 20.
so: (+ 10 11 12 13 14 15 16 17 18 19) = 145
NOTE:
- There is no need to sort this array.
- This can be solved in a single pass over the list.
- summation can only occur with two or more numbers.
Examples
(largestGapsum '(9 4 26 26 0 0 5 20 6 25 5))
> 145
(largestGapsum '(14 13 7 1 4 12 3 7 7 12 11 5 7))
> 27
; (+ 8 9 10)
(largestGapsum '(3 8 5 5 2 6 14 2 11 4 10 13 8 1 9))
> 0
; because the largest gap is only one number 12 and/or 7.
; and `sum` the addition of two or more numbers.
; (+ 12) and/or (+ 7)