Reported July 2026
DRWgreedy

Maximum Even-Sum Neighboring Pairs

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

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

DRW reported this one in July 2026, and it looks like a pair-matching puzzle until you see what it really is. Pair sums are even only when both numbers share parity, so you're cutting a circle into runs of same-parity elements and counting how many disjoint pairs fit inside each run. If you have the OA in a day or two, this is a short one to nail. StealthCoder sits invisibly as a safety net on the live OA if you blank on the circular edge case.

The problem

You are given N numbers on a circle, described by an integer array A. A neighboring pair is formed by two adjacent positions on the circle. This means positions i and i + 1 are neighbors, and the last position is also a neighbor of the first position.
Your task is to find the maximum number of neighboring pairs whose sums are even. Each array element can belong to at most one chosen pair.

Function
solution(A: int[]) → int

Examples
Example 1
A = [4,2,5,8,7,3,7]
return = 2
One optimal choice is (A[0], A[1]) and (A[4], A[5]). Another optimal choice is (A[0], A[1]) and (A[5], A[6]).
Choice 1: 4, 2, 5, 8, 7, 3, 7
Choice 2: 4, 2, 5, 8, 7, 3, 7
Example 2
A = [14,21,16,35,22]
return = 1
The only qualifying neighboring pair is (A[0], A[4]), using the circular adjacency between the first and last elements.
Circular pair: 14, 21, 16, 35, 22
Example 3
A = [5,5,5,5,5,5]
return = 3
All neighboring sums are even. We can create three non-overlapping pairs, for example (A[0], A[5]), (A[1], A[2]), and (A[3], A[4]).

Reported by candidates. Source: FastPrep

Pattern and pitfall

Reduce the array to parity. Adjacent elements form an even-sum pair only if they're both odd or both even. So split the circle into maximal runs of equal parity. A run of length L gives floor(L/2) disjoint adjacent pairs. Sum those across runs. The trap is the wraparound. If the first and last elements share parity, the first run and last run merge into one circular run, so you can't count them separately. If every element has the same parity, the whole circle is one run of N, and the answer is floor(N/2), which matches Example 3 giving 3 for six fives. Handle it by rotating the start to a parity boundary, or by merging the first and last run lengths. One linear pass, O(N) time, O(1) space. If the circular merge slips your mind mid-assessment, StealthCoder is the hedge that catches it live.

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 Maximum Even-Sum Neighboring Pairs 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 DRW's OA.

DRW 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.

Maximum Even-Sum Neighboring Pairs FAQ

What's the trick in the DRW maximum even-sum neighboring pairs problem?+

Convert every number to its parity. Two adjacent numbers sum to even only if their parities match. That turns the problem into splitting the circle into same-parity runs and taking floor(length/2) from each run, then summing the results.

How do I handle the circular wraparound?+

If the first and last elements have the same parity, their runs are really one run. Add the two lengths together before halving. If all elements share parity, the answer is just floor(N/2). Otherwise, start scanning at a parity change so no run gets split.

Why not just greedily pair left to right?+

On a line, greedy within a run is fine. On a circle, it can fail at the seam because you might pair a first element that should have been matched with the last. Merging the boundary runs first avoids that and gives the true maximum.

How hard is this really?+

Easy to medium. The logic is short, but the circular merge is where people lose points. Test Example 2, [14,21,16,35,22], where the only valid pair is the wraparound one, plus an all-same-parity array and a case with alternating parity.

How do I prepare for this in 48 hours?+

Write the solution twice from scratch. Run it by hand on the three given examples, then on edge cases: length 1, length 2, all even, strictly alternating. Alternating parity should return 0. Practice explaining why runs of length L give floor(L/2) pairs.

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

OA at DRW?
Invisible during screen share
Get it