Skip to content

1695. Maximum Erasure Value #1956

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 where all elements are unique. The solution involves efficiently scanning the array while maintaining a sliding window that ensures all elements within the window are distinct.

Approach

  1. Sliding Window Technique: We use two pointers, left and right, to represent the current window of elements. The right pointer expands the window by including new elements, while the left pointer contracts the window when a duplicate element is encountered.
  2. Frequency Tracking: A frequency array keeps track of the count of each element within the current window. This helps in quickly identifying duplicates.
  3. Sum Maintenance: As we expand the window by …

Replies: 1 comment 2 replies

Comment options

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

topugit Jul 22, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jul 22, 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 medium Difficulty
2 participants