Maximum Even-Sum Neighboring Pairs
Updated
Problem statement
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[]) → intExamples
Example 1
A = [4,2,5,8,7,3,7]return = 2One 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 = 1The 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 = 3All 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]).
More DRW Online Assessment questions
- Count Balanced Nodes in a Rooted TreeOA · Seen Sep 2026
- Largest Number With Even Digit FrequenciesOA · Seen Sep 2026
- Shortest Path Around Rectangular ObstaclesOA · Seen Sep 2026
- 2020 Account Balance with Monthly Card FeesOA · Seen Aug 2026
- Nested In-Memory Database TransactionsOA · Seen Aug 2026
- Password Requirement CheckOA · Seen Aug 2026
- Remove Excess Consecutive CharactersOA · Seen Aug 2026
- Last Round for Each PlayerOA · Seen Jul 2026
- Shortest Compressed Length After RemovalOA · Seen Jul 2026
- Doctor Appointment Slot AssignmentOA · Seen Jul 2026
Similar questions at other companies
- 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
- Maximum Even-Sum Adjacent Pairs in a Circular ArrayTesla · OATesla 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