Maximum Erasure Value | Java | Sliding Window | HashMap
public int maximumUniqueSubarray(int[] nums) {\n \n        int i=0;\n        int j=0;\n        int max=0;\n        int sum=0;\n        HashMap map = new HashMap
public int maximumUniqueSubarray(int[] nums) {\n \n        int i=0;\n        int j=0;\n        int max=0;\n        int sum=0;\n        HashMap<Integer, Integer> map = new HashMap<>();\n        while(j<nums.length)\n        {\n             map.put(nums[j], map.getOrDefault(nums[j],0)+1);\n             sum +=nums[j];\n            if(map.size()==j-i+1)\n            {\n                \n                max=Math.max(max,sum);\n                j++;\n            }\n            else if(map.size()<j-i+1){\n                while(map.size()<j-i+1){\n                 sum -=nums[i];\n                 map.put(nums[i], map.get(nums[i])-1);\n                 if(map.get(nums[i])==0){\n                   map.remove(nums[i]);\n                 }\n                 i++;\n                }\n                j++;\n            }\n             \n        }\n        return max;\n    }
['Sliding Window', 'Java']