Maximum Sequence Points

You are given an array of N integers. In each operation, you can pick any element x from the array, add x to your total score, and delete all occurrences of x-1 and x+1 from the array. The element x itself is also removed. This process continues until the array is empty. Return the maximum possible score you can achieve.

Example 1:

Input: [1,2]

Output: 2

Explanation:

  • Pick 2 → remove 1 → score = 2

Example 2:

Input: [1,2,3]

Output: 4

Explanation:

  • Pick 1 → score = 1
  • Pick 3 → score = 3
  • Total = 4

Now Your Turn!

Pick the correct output for the given input

Input: [1,2,1,3,2,2,2,2,3]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= N <= 105
  • 1 <= ai <= 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
long long maxSequencePoints(int n, vector<int>& arr) {
// Write your code here
return 0;
}
};
Test Case

Input:

Arr