Optimal C++ approach
\n\n# Code\n\nclass Solution {\npublic:    \n    int findMaximumLength(vector<int>& nums) {\n        int n = nums.size();\n        \n        // Create a prefix 
\n\n# Code\n```\nclass Solution {\npublic:    \n    int findMaximumLength(vector<int>& nums) {\n        int n = nums.size();\n        \n        // Create a prefix sum array to store cumulative sums of elements\n        vector<long long> pref(n + 1); // Using 1-based indexing\n        pref[0] = 0;\n        for(int i = 0; i < n; i++)\n            pref[i + 1] = pref[i] + nums[i]; // Calculate prefix sum\n        \n        // memoization to store information about subarray lengths and their sums\n        // dp[i].first: length of the longest subarray up to index i\n        // dp[i].second: sum of the elements in the longest subarray up to index i\n        vector<pair<int, long long>> dp(n + 2); // Using 1-based indexing\n        \n        // Initializing dpization for the base case\n        dp[0].first = 1; // Length of an empty array is 1\n        for(int i = 1; i <= n; i++) {\n            // Update the dpization array\n            dp[i] = max(dp[i], dp[i - 1]); // Update the length of subarray at index i\n            \n            // Finding the index where the subarray with equal parts sums ends\n            int idx = lower_bound(pref.begin(), pref.end(), 2 * pref[i] - dp[i].second) - pref.begin();\n            \n            // Update the dpization if a longer subarray with equal parts sums is found\n            dp[idx] = max(dp[idx], {dp[i].first + 1, pref[i]}); // Update length and sum information\n        }\n        return dp[n].first; // Return the length of the longest subarray with equal parts sums\n    }\n};\n\n```
['C++']