Java | Sliding Window | HashMap
\nclass Solution {\n    public int maximumUniqueSubarray(int[] arr) {\n        Map<Integer,Integer> mp = new HashMap<>();\n        int j = 0;\n        int i = 0
```\nclass Solution {\n    public int maximumUniqueSubarray(int[] arr) {\n        Map<Integer,Integer> mp = new HashMap<>();\n        int j = 0;\n        int i = 0;\n        int sum = 0;\n        int max = Integer.MIN_VALUE;\n        while(j < arr.length){\n          sum = sum + arr[j];\n          //insert into map\n          if(mp.containsKey(arr[j])){\n            mp.put(arr[j],mp.get(arr[j]) + 1);\n          }\n          else{\n            mp.put(arr[j],1);\n          }\n          //map size with window size\n          if(j - i + 1 == mp.size()){\n             max = Math.max(max,sum);\n          }\n         else if(j - i + 1 > mp.size()){\n           //slide your window until you found the unique elements subarray\n              while(j - i + 1 > mp.size()){\n              sum = sum - arr[i];\n              if(mp.containsKey(arr[i])){\n                \n                int freq = mp.get(arr[i]);\n                freq--;\n                if(freq == 0) mp.remove(arr[i]);\n                else          mp.put(arr[i],freq);\n                \n              }\n                i++;\n              }\n           \n            \n         \n          }\n         j++; \n        }\n      \n      return max;\n    }\n}\n```
[]