Max Sum With No Two Adjacent Picks on a Circle
Updated
Problem statement
The numbers in values are placed around a circle in index order. Indexes that come one right after the other are neighbors. The circle closes on itself, so the last index, values.length - 1, and index 0 are neighbors too. For example, with 4 values the neighbor pairs are (0, 1), (1, 2), (2, 3) and (3, 0).
Choose a group of indexes that contains no neighbor pair, and add up the values at those indexes. Return the largest sum any such group can have.
An array with one number has no neighbor pair at all, so its only number may be chosen.
Function
maxPickSumCircle(values: int[]) → intExamples
Example 1
values = [8,1,3,7]return = 11On a line, indexes 0 and 3 would give 8 + 7 = 15. On a circle, index 3 is next to index 0, so that pair is not allowed.
The best allowed pair is indexes 0 and 2: 8 + 3 = 11. The other allowed pair, indexes 1 and 3, gives only 1 + 7 = 8.
Example 2
values = [5,4,6,4,5]return = 11Indexes 0, 2 and 4 would give 16, but indexes 4 and 0 are neighbors on the circle.
With five values on a circle, at most two can be picked. The best pair is indexes 0 and 2 (or 2 and 4): 5 + 6 = 11.
Example 3
values = [12]return = 12A single value has no neighbor, so pick it.
Constraints
1 <= values.length <= 10000 <= values[i] <= 10^4
More DocuSign Online Assessment questions
- Max Sum With No Two Adjacent PicksOA · Seen Apr 2026
- Beautiful Number OrderingsOA · Seen Feb 2026
- Grid Path With the Most ClearanceOA · Seen May 2025
- Vehicle Mixes for a Wheel TotalOA · Seen May 2025
- Count Sales Rung Up at the Wrong PriceOA · Seen Feb 2021
- Most Disjoint Intervals From Starts and DurationsOA · Seen Feb 2021
- Fewest Fountains to Water the GardenOA · Seen Feb 2021
- Lowest Start That Keeps Running Totals PositiveOA · Seen Feb 2021
- Fewest Student Groups Within a Level GapOA · Seen Nov 2020
- Alphabetize a Word ListOA · Seen May 2020
Similar questions at other companies
- 0/1 KnapsackConfluent · OAConfluent interview questions
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Maximum Subarray SumStraive · OA
- Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
- Lowest-Cost Shirt Color ScheduleElevenLabs · OAElevenLabs interview questions
- Maximum Game Board ScoreJP Morgan Chase · OAJP Morgan Chase interview questions
- API Bandwidth AllocationArista Networks · OAArista Networks interview questions
- Maximum Points by Deleting ElementsIBM · OAIBM interview questions
- House RobberWalmart · OAWalmart interview questions