Java HashMap
\nclass Solution {\n   // left[i] is the size of the min size subarray in arr[0, i] that sums up to target. Is Integer.MAX_VALUE if there is no subarray that su
```\nclass Solution {\n   // left[i] is the size of the min size subarray in arr[0, i] that sums up to target. Is Integer.MAX_VALUE if there is no subarray that sums up to target.\n// right[i] is the size of the min size subarray in arr[i, arr.length - 1] that sums up to target.\n// for (int i = 1; i < arr.length; ++i) result = Math.min(result, left[i - 1] + right[i]);\npublic int minSumOfLengths(int[] arr, int target) {          \n    int[] left = new int[arr.length];\n    int sum = 0, best = Integer.MAX_VALUE;\n    Map<Integer, Integer> map = new HashMap<>();\n    map.put(0, -1);   \n    for (int i = 0; i < arr.length; ++i) {\n        sum += arr[i];\n        if (map.containsKey(sum - target)) {\n            best = Math.min(best, i - map.get(sum - target));  \n        }\n        left[i] = best;\n        map.put(sum, i);    \n    }\n    \n    int[] right = new int[arr.length];\n    sum = 0; best = Integer.MAX_VALUE;\n    map = new HashMap<>();\n    map.put(0, arr.length);    \n    for (int i = arr.length - 1; i >= 0; --i) {\n        sum += arr[i];\n        if (map.containsKey(sum - target)) {\n            best = Math.min(best, map.get(sum - target) - i); \n        }\n        right[i] = best;\n        map.put(sum, i);  \n    }\n    \n    int result = Integer.MAX_VALUE;\n    for (int i = 1; i < arr.length; ++i) {\n        if (left[i - 1] != Integer.MAX_VALUE && right[i] != Integer.MAX_VALUE) {\n            result = Math.min(result, left[i - 1] + right[i]);  \n        }\n    }\n    return result == Integer.MAX_VALUE ? -1 : result;\n}\n}\n```
[]