Alternating Sum
For an array $A$, we define $\text{score}(A)$ as $\sum_{i = 1}^{|A|} (-1)^i \cdot A_i$, i.e. alternating sum of its elements. Note that the score of an empty array is $0$. Further, we define $f(A)$ as the maximum value of $\text{score}(B)$ over all $B$ which are subsequences$^{\dagger}$ of $A$. Here, it is allowed for $B$ to be empty. You are given an array of $N$ integers - $[A_1, A_2, \ldots,
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start