[C++] Subarray with sum equals target TWICE!
In this approach I first find the smallest subarray of sum as target and then remove that, then from the updated array I again find the subarray of sum as targe
In this approach I first find the smallest subarray of sum as target and then remove that, then from the updated array I again find the subarray of sum as target. Finally return the sum of both subarray lengths.\n```\nclass Solution {\npublic:\n    vector<int> f(vector<int>&A, int s)\n    {\n        unordered_map<int, int> mp;\n        mp[0] = -1;\n        int sum = 0, len = INT_MAX, si = -1, sj = -1;\n        for(int i = 0; i < A.size(); i++)\n        {\n            sum += A[i];\n            if(mp.find(sum - s) != mp.end())\n            {\n                int id = mp[sum - s];\n                int l = i - id;\n                if(l < len)\n                {\n                    len = l;\n                    si = id + 1;\n                    sj = i;\n                }\n            }\n            mp[sum] = i;\n        }\n        return {si, sj};\n    }\n    int minSumOfLengths(vector<int>& A, int target) {        \n        vector<int> v = f(A, target);\n        if(v[0] == -1 && v[1] == -1)\n            return -1;\n        vector<int> B;\n        for(int i = 0; i < A.size(); i++)\n        {\n            if(i >= v[0] && i <= v[1])\n                continue;\n            B.push_back(A[i]);\n        }\n        vector<int> v1 = f(B, target);\n        if(v1[0] == -1 && v1[1] == -1)\n            return -1;\n        return (v[1] - v[0] + 1) + (v1[1] - v1[0] + 1);\n    }\n};\n```
[]