Reported October 2021
Teslaarray

Maximum Even-Sum Adjacent Pairs in a Circular Array

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

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

The trap in this Tesla OA, reported in October 2021, is the wraparound edge. A greedy left-to-right scan passes the linear cases and then quietly fails the circular one. The problem gives you a circular array and asks for the maximum number of disjoint adjacent pairs whose sum is even. It's an array problem that turns into parity runs once you see it. If you blank on the circular handling during the live assessment, StealthCoder is the safety net that sits invisibly on your screen and gives you a working solution.

The problem

You are given a circular array of integers nums. Indices i and (i + 1) mod n are adjacent.
Choose as many disjoint adjacent pairs as possible such that the sum of the two values in every chosen pair is even. Each array element may belong to at most one chosen pair.
Return the maximum possible number of pairs.

Function
maxEvenSumPairs(nums: int[]) → int

Examples
Example 1
nums = [5,7,9,6,3]
return = 2
Choose the wraparound pair (5, 3) and the adjacent pair (7, 9).
Example 2
nums = [1,1,1,1,1,1]
return = 3
Pair consecutive elements without using the wraparound edge. All three sums are even.
Example 3
nums = [1,2,3,4]
return = 0
Every adjacent pair contains one odd and one even value, so every adjacent sum is odd.

Constraints
1 <= nums.length <= 2 * 10^5.
-10^9 <= nums[i] <= 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Two numbers sum to even only when they share parity. So an adjacent pair is valid when both values are odd or both are even. Split the circle into maximal runs of equal parity. A run of length L gives floor(L/2) disjoint pairs, since pairs inside a run can't cross into a different parity. The pitfall is the wrap. If the first and last elements share parity, the run at the end and the run at the start are really one run, so merge them before dividing by two. Merging matters when both are odd lengths: 3 and 3 give 1+1=2 separately but 3 when merged. Also handle the case where the whole array is one parity: the answer is floor(n/2), because a full circle doesn't need the wrap. It's O(n) time, O(1) space. Use x % 2 != 0 for negatives, not x % 2 == 1. If you freeze on the merge logic in the OA, StealthCoder is your hedge.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Maximum Even-Sum Adjacent Pairs in a Circular Array 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Tesla reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Even-Sum Adjacent Pairs in a Circular Array FAQ

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

Even sum means same parity. Break the circle into runs of equal parity, add floor(length/2) per run, and merge the first and last runs if their parity matches. The merge is the whole difficulty, and it's what separates a pass from a partial score.

How do I handle the circular wraparound?+

Find a spot where adjacent parities differ and start your scan right after it. Then the runs never straddle the array boundary. If no such spot exists, every element has the same parity and the answer is n // 2.

Why do negative numbers matter here?+

In some languages, -3 % 2 returns -1, so a check like x % 2 == 1 misses negative odds. Use x % 2 != 0, or x & 1. The constraints allow values down to -10^9, so this will be tested.

How hard is this really?+

Easy to medium. The idea is short, but the circular edge case and the run-merging catch people who only tested the sample inputs. Write out your own case like [1,1,1,2,1,1,1] and check it by hand.

How do I prepare in 48 hours for a problem like this?+

Practice parity and run-length reasoning on circular arrays. Code the linear version first, then add the wrap. Test with all-same parity, alternating parity, length 1, and odd-length runs at both ends. That covers nearly every failure mode.

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

OA at Tesla?
Invisible during screen share
Get it