Maximum Unique Subarray Sum After Deletion

You are given an integer array nums.

You are allowed to delete any number of elements from nums without making it empty. After performing the deletions, select a subarray of nums such that:

  • All elements in the subarray are unique.
  • The sum of the elements in the subarray is maximized.

Return the maximum sum of such a subarray.

Example 1
Inputnums = [1,2,3,4,5]
Output15
Select the entire array without deleting any element to obtain the maximum sum.
Example 2
Inputnums = [1,1,0,1,1]
Output1
Delete the extra 1 values and 0, then select the remaining array [1] to obtain the maximum sum.

Constraints

  • 1 <= nums.length <= 100
  • -100 <= nums[i] <= 100

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate