Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created July 25, 2025 15:53
Show Gist options
  • Save Ifihan/74439e93fcf3a4834438b633dae29714 to your computer and use it in GitHub Desktop.
Save Ifihan/74439e93fcf3a4834438b633dae29714 to your computer and use it in GitHub Desktop.
Maximum Unique Subarray Sum After Deletion

Question

Approach

I used a sliding window technique to maintain a subarray where all the elements are unique. I kept a set called seen to quickly check for duplicates and removed elements from the left of the window if a duplicate was encountered. For each unique window, I maintained the sum and updated the maximum sum encountered so far.

It didn't work and I checked the editorial, and it was a one-liner???

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment