Reported September 2024
ZipRecruiterarray

Filtered Even- Minus Odd-Index Sums

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this ZipRecruiter OA, reported in September 2024, is reindexing after the filter. Don't. The problem says to use each retained value's original zero-based index, so a skipped element still burns its slot. It's a single-pass array problem with a parity check, and the whole difficulty is that one trap. If you read it fast and filter into a new list first, your answers drift on any input with out-of-range values. StealthCoder is the safety net if you blank on the live OA. It sits invisible on screen and hands you the clean loop.

The problem

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

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to never build a filtered array. Loop once over the original array with the original index i. If values[i] is between -100 and 100 inclusive, add it when i is even and subtract it when i is odd. That's O(n) time and O(1) space. The pitfall is filtering first, then using the new index, which flips parity for everything after a removed element. Check Example 1: 101 is dropped at index 0, but 3 stays at index 1 and counts as odd. Even sum is 4+2=6, odd sum is 3+5=8, result -2. Other things to watch: an empty array returns 0, and the inclusive bounds matter, so -100 and 100 both stay. Sums fit easily since retained values are tiny, but use a normal int or long anyway. If your head goes blank mid-OA, StealthCoder is the hedge that gives you this loop in seconds.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Filtered Even- Minus Odd-Index Sums cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Filtered Even- Minus Odd-Index Sums FAQ

How hard is this ZipRecruiter OA question really?+

Easy. It's a single loop with a range check and a parity check. The only real risk is misreading the index rule. If you write it in under ten minutes and test both examples, you're fine. Spend the leftover time on edge cases.

What's the trick to filteredParityDifference?+

Keep the original index. Don't copy retained values into a new array, because that shifts parity. Iterate with i, skip values outside [-100, 100], then add on even i and subtract on odd i. One pass, constant space.

What edge cases should I test?+

Test an empty array, which should return 0. Test values exactly at -100 and 100, which are retained. Test a dropped element at the front, like Example 1, to confirm odd indices stay odd. Also test all values out of range, which gives 0.

Do I need to worry about overflow with values up to 1e9?+

Not really. Anything outside [-100, 100] is ignored, so retained values are tiny and the sum is at most about 100 times 100000. Plain int is safe. Using long costs nothing if you want to be careful.

How do I prepare for this in 48 hours?+

Don't grind. Write this loop once from memory, then do a few array-with-condition problems where index handling matters. Practice reading the statement twice before coding, since the trap is in the wording, not the algorithm.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it