Loading problem...
You are given an array of positive integers representing point values of collectible items. Your objective is to maximize the total points gathered by strategically selecting items from this collection.
When you select an item with value v, you immediately earn v points. However, the selection comes with a consequence: all items with values v - 1 and v + 1 are immediately removed from the collection (they become unavailable for future selection). This simulates a competitive or conflict-based point collection scenario where choosing one type of item excludes its immediate numerical neighbors.
You may perform this selection operation as many times as you wish, as long as there are items remaining in the collection. Each item can only be selected (and earn points) once. The challenge lies in determining which items to select to maximize the total accumulated points.
Return the maximum total points you can accumulate by optimally performing the selection operations.
nums = [3,4,2]6One optimal strategy:
nums = [2,2,3,3,3,4]9One optimal strategy:
nums = [5]5With only a single item in the collection, select it to earn 5 points.
Constraints