Prefix Sum Approach | Beats both runtime and memory by 100%
Using prefix sum and simply checking if two subarrays are equal by substracting values.\nUpvote if this helps you :)\n\n\n\n\n\nC++ code:\n\nclass Solution {\np
Using prefix sum and simply checking if two subarrays are equal by substracting values.\nUpvote if this helps you :)\n\n![image](https://assets.leetcode.com/users/images/dfaceb68-ce35-42d3-bc9c-bdfac2a71c98_1662374864.870948.png)\n\n\n\nC++ code:\n```\nclass Solution {\npublic:\n    bool findSubarrays(vector<int>& nums) {\n        int n=nums.size();\n        vector<long long int> prefix(n+1,0);\n        prefix[0]=0;\n        for(int i=0;i<n;i++){\n            prefix[i+1]=prefix[i]+nums[i];\n        }\n        \n        for(int i=1;i<n-1;i++){\n            long long int curr=prefix[i+1]-prefix[i-1];\n            for(int j=i+1;j<n;j++){\n                long long int next=prefix[j+1]-prefix[j-1];\n                if(next==curr)\n                    return true;\n            }\n        }\n        \n        return false;\n    }\n};\n```\n\nWorst case cpmplexity analysis:\n1. Space O(n)\n2. Time O(n^2)\n\nPlease feel free to comment if you have any doubts.
['Array', 'C', 'Prefix Sum']