Analytical
Problems that require the answerer to reason about some equation or compute some quantity in order to solve them but don’t really fit firmly in any other solution methods.
Sum of Odds & Evens Equal After Removal
Given an array of integers, choose one indices to remove that makes the even indexed elements sum to the same value as the odd index elements. Return the total number of indices that can be removed in this way.
Explore
6 1 7 4 1
csl -> 6,0 6,1 13,1 13,5 14,5
csr -> 1,0 1,4 8,4 8,5 14,5
- Calculate the cumulative sum from the left & right of odd & even indices.
- For all i, compare csl[i-1]→even + csr[i+1]→odd to csl[i-1]→odd + csr[i+1]→even because removing one index from csr swaps even & odd sums.
- Return the number of comparisons that return true.
Python Solution
Complexity
We calculate the cumulative sums from the left & the right using O(n) space & then iterate them to find which indices can be removed in O(n) total time.
Left & Right Sum Differences
Given an array of integers, find the difference in the absolute value of the cumulative sum from the left & the right at each index. The value at the current index is not included in the calculations.