Problem
Maximum Score With Non-Adjacent Values
Learn this problemProblem statement
You are given a list of integers nums. You may choose any set of values from the list.
If you choose a value x, then you cannot choose x - 1 or x + 1. When you choose x, your score increases by x * frequency(x), where frequency(x) is the number of times x appears in nums.
Return the maximum score you can obtain.
Function
maximumNonAdjacentValueScore(nums: int[]) → longExamples
Example 1
nums = [3,4,2]return = 6Choose values 2 and 4 for score 2 + 4 = 6. Choosing 3 would block both.
Example 2
nums = [2,2,3,3,3,4]return = 9Choosing value 3 gives score 3 * 3 = 9, which is better than choosing 2 and 4 for score 8.
Constraints
nums.length >= 1
More Amazon problems
- HTTP Request RedirectionOA · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Permutation SorterOA · Seen Jul 2026
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026