even
and odd
, to represent the maximum alternating sum ending with a positive sign and a negative sign, respectively.nums
.a
in nums
, update even
to be the maximum of even
and odd + a
.odd
to be even - a
.even
will hold the maximum alternating sum of any subsequence.