Maximum Even-Sum Adjacent Pairs in a Circular Array
Updated
Problem statement
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[]) → intExamples
Example 1
nums = [5,7,9,6,3]return = 2Choose the wraparound pair (5, 3) and the adjacent pair (7, 9).
Example 2
nums = [1,1,1,1,1,1]return = 3Pair consecutive elements without using the wraparound edge. All three sums are even.
Example 3
nums = [1,2,3,4]return = 0Every 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.
More Tesla interview questions
- Count Zero-Sum FragmentsOA · Seen Jun 2026
- Maximum Insertions Without Three Consecutive AOA · Seen Jun 2026
- Maximum Number of Workers with Equal Left and Right ShoesOA · Seen Mar 2025
- Flatten a Branched List into a Doubly Linked ListPHONE SCREEN · Seen Sep 2026
- Reduce-Based Map and Filter PipelinePHONE SCREEN · Seen Sep 2026
- Resilient Fake API ClientPHONE SCREEN · Seen Sep 2026
- Alternate Positive and Negative ValuesONSITE INTERVIEW · Seen Aug 2026
- Enumerate Character Paths to a MarkerONSITE INTERVIEW · Seen Aug 2026
- Shared Counter Snapshot SumONSITE INTERVIEW · Seen Aug 2026
- Merge JSON Array FieldsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Maximum Even-Sum Neighboring PairsDRW · OADRW interview questions
- Minimize Total Input Cost (for LTMS)Salesforce · OASalesforce interview questions
- Maximize Protected City PopulationAmazon · OA
- Network FormationPalantir · OAPalantir interview questions
- Maximum Even Subsequence SumExpedia · OAExpedia interview questions
- Fewest Fountains to Water the GardenDocuSign · OADocuSign interview questions
- Minimum Jumps to Reach the EndNutanix · OANutanix interview questions
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
- Split Array Largest SumAuxoAI · OA
- Maximum Income from Asset TradingJefferies · OA
Tesla interview experiences
- Tesla Experienced Infrastructure SWE Interviews: 1 Experience
- Tesla Older SWE Intern Reports: 14 Experiences (Part 4 of 4)
- Tesla Embedded and SRE Intern Loops: 15 Experiences (Part 3 of 4)
- Tesla SWE and Data Intern Rounds: 10 Experiences (Part 2 of 4)
- Tesla Intern Python Interview Prep Guide
- 2017–2026 Tesla Intern OA / Interviews: 83 Experiences (Part 2 :)