You are given an array of positive integers nums and want to erase a subarray containing&nbsp;unique elements. The score you get by erasing the subarray is equal to the sum of its elements.

Return the maximum score you can get by erasing exactly one subarray.

An array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).

&nbsp;
Example 1:

Input: nums = [4,2,4,5,6]
Output: 17
Explanation: The optimal subarray here is [2,4,5,6].


Example 2:

Input: nums = [5,2,1,2,5,2,1,2,5]
Output: 8
Explanation: The optimal subarray here is [5,2,1] or [1,2,5].


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	1 &lt;= nums[i] &lt;= 104


class Solution:
    def maximumUniqueSubarray(self, nums: List[int]) -> int:
        max_sum = 0
        seen = set()
        for l in range(len(nums)):
            seen.clear()
            curr_sum = 0
            r = l
            while r < len(nums):
                if nums[r] in seen:
                    break
                curr_sum += nums[r]
                seen.add(nums[r])
                r += 1
            max_sum = max(max_sum, curr_sum)
        return max_sum
class Solution {
    public int maximumUniqueSubarray(int[] nums) {
        short[] nmap = new short[10001];
        int total = 0, best = 0;
        for (int left = 0, right = 0; right < nums.length; right++) {
            nmap[nums[right]]++;
            total += nums[right];
            while (nmap[nums[right]] > 1) {
                nmap[nums[left]]--;
                total -= nums[left++];
            }
            best = Math.max(best, total);
        }
        return best;
    }
}
class Solution {
public:
    int maximumUniqueSubarray(vector<int>& nums) {
        int curr_sum=0, res=0;

        //set to store the elements
        unordered_set<int> st;

        int i=0,j=0;
        while(j<nums.size()) {
            while(st.count(nums[j])>0) {
                //Removing the ith element untill we reach the repeating element
                st.erase(nums[i]);
                curr_sum-=nums[i];
                i++;
            }
            //Add the current element to set and curr_sum value
            curr_sum+=nums[j];
            st.insert(nums[j++]);

            //res variable to keep track of largest curr_sum encountered till now...
            res = max(res, curr_sum);
        }

        return res;
    }
};
var maximumUniqueSubarray = function(nums) {
    let nmap = new Int8Array(10001), total = 0, best = 0
    for (let left = 0, right = 0; right < nums.length; right++) {
        nmap[nums[right]]++, total += nums[right]
        while (nmap[nums[right]] > 1)
            nmap[nums[left]]--, total -= nums[left++]
        best = Math.max(best, total)
    }
    return best
};
Maximum Erasure Value