FastPrepMaximum Score With Non-Adjacent Values
Problems/Maximum Score With Non-Adjacent Values

Maximum Score With Non-Adjacent Values

Amazon logoAmazonFULLTIMEONSITE INTERVIEW

Updated Jul 2026

QuestionFunctionExamplesConstraints

Problem 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[]) → long

Examples

Example 1

nums = [3,4,2]return = 6

Choose values 2 and 4 for score 2 + 4 = 6. Choosing 3 would block both.

Example 2

nums = [2,2,3,3,3,4]return = 9

Choosing value 3 gives score 3 * 3 = 9, which is better than choosing 2 and 4 for score 8.

Constraints

  • nums.length >= 1

More Amazon Onsite Interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public long maximumNonAdjacentValueScore(int[] nums) {
      // write your code here
    }
}
Checking account…