Skip to content

3487. Maximum Unique Subarray Sum After Deletion #1968

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find the maximum sum of a contiguous subarray after deleting any number of elements (without making the array empty) such that all elements in the subarray are unique. The solution leverages the observation that if the maximum element in the array is negative, the answer is simply that maximum element. Otherwise, the solution involves summing all distinct non-negative elements in the array, as these can always be arranged into a contiguous subarray with unique elements after appropriate deletions.

Approach

  1. Check for All Negative Elements: If the maximum element in the array is negative, the solution is that maximum element since any subarray containing it would not yield a hig…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Jul 25, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jul 25, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants