Maximum Erasure Value LeetCode solution in Java
1class Solution {2public int maximumUniqueSubarray(int[] nums) {3short[] nmap = new short[10001];4int total = 0, best = 0;5for (int left = 0, right = 0; right < nums.length; right++) {6nmap[nums[right]]++;7total += nums[right];8while (nmap[nums[right]] > 1) {9nmap[nums[left]]--;10total -= nums[left++];11}12best = Math.max(best, total);13}14return best;15}16}