Skip to content

Practice Delete and Earn

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#740
LeetCode Problem

Delete and Earn

Problem Statement

You may repeatedly choose one occurrence of a value v in nums, remove it and earn v points. That choice also removes every occurrence of v - 1 and v + 1, without earning their points. Other copies of v remain available. Return the greatest total points obtainable.

Source: Delete and Earn on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3,4,2]
Output
6

# Example 2

Input
nums = [2,2,3,3,3,4]
Output
9

Constraints

1 <= nums.length <= 2 * 10^4
1 <= nums[i] <= 10^4

Related LeetCode Problems

Practice more problems similar to Delete and Earn.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.