Difference Between Sums of Positions
note - see the Problem Source below for the original problem description ;)
Imagine you’re given a list of numbers, and your task is to calculate the difference between two specific sums. First, you’ll sum up all the numbers at even positions (remember, the list is 0-based) that fall between -100 and 100, inclusive. Then, you’ll do the same for numbers at odd positions that also lie within this range. Finally, you’ll subtract the odd-positioned sum from the even-positioned sum to get your answer. Just make sure your solution is efficient, ideally not taking more than O(n) time, though a slightly slower approach will also work fine.
1Example 1
2Example 2
3Example 3
Constraints
Limits and guarantees your solution can rely on.
1 ≤ numbers.length ≤ 10^3-10^3 ≤ numbers[i] ≤ 10^3