Max Sum With No Two Adjacent Picks
Updated
Problem statement
You are given an integer array values. You may pick any set of positions in the array, but you may never pick two positions that are next to each other, such as positions i and i + 1.
Return the largest possible sum of the picked values. Picking nothing is allowed and gives a sum of 0.
Function
maxPickSum(values: int[]) → intExamples
Example 1
values = [4,1,2,9,3]return = 13Pick indexes 0 and 3: 4 + 9 = 13. They are not next to each other.
Index 4 cannot be added, because it is next to index 3. Every other allowed set is smaller, for example indexes 0, 2 and 4 give 4 + 2 + 3 = 9.
Example 2
values = [3,8,4]return = 8Picking both ends gives 3 + 4 = 7. Picking the middle value alone gives 8, which is larger.
Example 3
values = [12]return = 12There is only one value and nothing next to it, so pick it.
Constraints
1 <= values.length <= 10000 <= values[i] <= 10^4
More DocuSign Online Assessment questions
- Max Sum With No Two Adjacent Picks on a CircleOA · 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