Java || HashMap || O(N) solution || Single Iteration
\nclass Solution {\n    public int maximumUniqueSubarray(int[] nums) {\n        HashMap<Integer,Integer>loc=new HashMap<>(); //stores the index of last occurran
```\nclass Solution {\n    public int maximumUniqueSubarray(int[] nums) {\n        HashMap<Integer,Integer>loc=new HashMap<>(); //stores the index of last occurrance of the number\n        HashMap<Integer,Integer>sum=new HashMap<>(); //stores the prefix sum\n        int ans=0;//stores the final answer\n        int total=0;//stores the sum upto the index\n        int idx=-1;//stores the starting index from which the subarray has to be considered\n        for(int i=0;i<nums.length;i++)\n        {\n            total+=nums[i];//calculating total sum\n            if(loc.containsKey(nums[i])) //if the number repeats update the starting index of subarray\n                idx=Math.max(idx,loc.get(nums[i]));\n            if(idx==-1)\n                ans=Math.max(ans,total);\n            else\n                ans=Math.max(ans,total-sum.get(idx));//subtract prefix sum of starting of subarray from total to get sum of subarray\n            loc.put(nums[i],i);//update last occurance of the number\n            sum.put(i,total);//update prefix sum\n        }\n        return ans;\n    }\n}\n```
['Prefix Sum', 'Java']