FastPrepFiltered Even- Minus Odd-Index Sums

Filtered Even- Minus Odd-Index Sums

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

You are given an integer array values. Ignore every value outside the inclusive range [-100, 100].

Using each retained value's original zero-based index, return the sum at even indices minus the sum at odd indices.

Function

filteredParityDifference(values: int[]) → int

Examples

Example 1

values = [101,3,4,359,2,5]return = -2

The retained even-index values total 6 and the retained odd-index values total 8, so the result is -2.

Example 2

values = [-100,100,-101,0]return = -200

Indices 0, 1, and 3 are retained: -100 - 100 - 0 = -200.

Constraints

  • 0 <= values.length <= 100000
  • -1000000000 <= values[i] <= 1000000000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int filteredParityDifference(int[] values) {
    // Write your code here.
}
values[101,3,4,359,2,5]
expected-2
Checking account…