DatabricksOA #16
Difference Between Sums of Positions
Estimated EasyJudge-ready
Topics (AI-labelled)In-place Arrays
Given an array numbers, consider only the elements whose value lies in the closed interval [-100,100]. Compute the sum of such elements at 0-based even indices and the sum at odd indices, and output the former minus the latter.
Standard input/output and this site's supplementary ranges follow this problem's description.
Input
The first line contains n (1≤n≤1000), and the second line contains n integers, −1000≤numbers[i]≤1000.
Output
Output the filtered even-index sum minus the filtered odd-index sum, as one integer.
Example 1
Input:
6
101 3 4 359 2 5
Output:
-2
Example 2
Input:
6
-2 234 100 99 540 -1
Output:
0
Example 3
Input:
1
-9
Output:
-9
Editorial
Loading solution…