Search
⌘K

Leetcode 2036. Maximum Alternating Subarray Sum

Find the contiguous subarray that maximizes the alternating sum formed by adding and subtracting consecutive elements (a[i] - a[i+1] + a[i+2] - ...). The core challenge is an O(n) Kadane-like/two-state DP to track the best ending sums when the next element is added or subtracted.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.